Skip to content

Commit

Permalink
[1.2.0] Add watched/unwatched change status button on medias
Browse files Browse the repository at this point in the history
  • Loading branch information
yanncam committed Nov 12, 2017
1 parent 75129b9 commit 8b7c10e
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
define("NAX_TVSHOWSEASON_VIEW","season_view");
define("NAX_TVSHOWEPISODE_VIEW","episode_view");
define("ENABLE_AUTHENTICATION", (ENABLE_INTERNAL_AUTHENTICATION || ENABLE_LDAP_AUTHENTICATION));
define("KODI_WEB_PORTAL_VERSION", "1.1.8");
define("KODI_WEB_PORTAL_VERSION", "1.2.0");
define("IS_INCLUDED", true);

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
Expand Down
81 changes: 69 additions & 12 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,56 @@ function showsize($file) {
return $return;
}

function changeStatusMovie($id, $toStatus){
global $db, $WATCH_STATUS_FOR_USERS;
if($toStatus === "toWatched"){
$playCount = 1;
$lastPlayed = date("Y-m-d H:i:s", time());
} else {
$playCount = NULL;
$lastPlayed = NULL;
}
$sql = "UPDATE
" . NAX_MOVIE_VIEW . "
SET
" . NAX_MOVIE_VIEW . ".playCount = :playCount,
" . NAX_MOVIE_VIEW . ".lastPlayed = :lastPlayed
WHERE
" . NAX_MOVIE_VIEW . ".idMovie = :id;";
$stmt = $db->prepare($sql);
$stmt->bindValue('playCount', $playCount, PDO::PARAM_INT);
$stmt->bindValue('lastPlayed', $lastPlayed, PDO::PARAM_STR);
$stmt->bindValue('id', $id, PDO::PARAM_INT);
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
$stmt->execute();
}
}

function changeStatusEpisode($id, $toStatus){
global $db, $WATCH_STATUS_FOR_USERS;
if($toStatus === "toWatched"){
$playCount = 1;
$lastPlayed = date("Y-m-d H:i:s", time());
} else {
$playCount = NULL;
$lastPlayed = NULL;
}
$sql = "UPDATE
" . NAX_TVSHOWEPISODE_VIEW . "
SET
" . NAX_TVSHOWEPISODE_VIEW . ".playCount = :playCount,
" . NAX_TVSHOWEPISODE_VIEW . ".lastPlayed = :lastPlayed
WHERE
" . NAX_TVSHOWEPISODE_VIEW . ".idEpisode = :id;";
$stmt = $db->prepare($sql);
$stmt->bindValue('playCount', $playCount, PDO::PARAM_INT);
$stmt->bindValue('lastPlayed', $lastPlayed, PDO::PARAM_STR);
$stmt->bindValue('id', $id, PDO::PARAM_INT);
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
$stmt->execute();
}
}

/**
* Return HTML formated result of movies entries to display in the main page.
* Results depend on the $sql query passed in argument.
Expand All @@ -266,20 +316,25 @@ function getEntriesMovies($sql){
$playedStatus = "unwatched";
if(intval($data["playCount"]) > 0)
$playedStatus = "watched";
$switchStatus = ($playedStatus === "watched") ? "unwatched" : "watched";
?>
<div class="entry arrondi" id="<?php echo $data["idMovie"]; ?>">
<div class="fanart arrondi"><img class="arrondi" src="<?php echo $fanarts[0]; ?>" onerror="this.src='images/fanart-onerror.png';" style="display:none;" /></div>
<div class="title"><?php echo $data["movieTitleFR"] . " ($year)"; ?></div>
<img class="thumb arrondi" src="<?php echo $thumbs[0]; ?>" onerror="this.src='images/thumb-onerror.jpg';" style="display:none;" />
<?php
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
?>
<img class="thumbStatus arrondiTopLeft"src="images/<?php echo $playedStatus; ?>.png" title="<?php echo $playedStatus; ?>" style="display:none;" />
<?php
}
?>
<?php if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){ ?>
<div id="cornerStatus_<?php echo $data["idMovie"]; ?>_unwatched" style="cursor:pointer;display:<?php echo ($playedStatus == "unwatched") ? "visible" : "none"; ?>"><img class="thumbStatus arrondiTopLeft"src="images/unwatched.png" title="<?php echo STATUS_UNWATCHED_LABEL; ?>" style="display:none;" /></div>
<div id="cornerStatus_<?php echo $data["idMovie"]; ?>_watched" style="cursor:pointer;display:<?php echo ($playedStatus == "watched") ? "visible" : "none"; ?>"><img class="thumbStatus arrondiTopLeft"src="images/watched.png" title="<?php echo STATUS_WATCHED_LABEL; ?>" style="display:none;" /></div>
<?php } ?>
<div class="synopsis"><?php echo $data["movieSynopsis"]; ?></div>
<div class="toolbar">
<?php
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
?>
<a id="linkStatus_<?php echo $data["idMovie"]; ?>_unwatched" onclick="changeStatus('toWatched', <?php echo $data["idMovie"]; ?>);" style="position:absolute;float:left;cursor:pointer;display:<?php echo ($playedStatus == "unwatched") ? "block" : "none"; ?>"><img id="buttonStatus_<?php echo $data["idMovie"]; ?>" src="images/unwatchedButton.png" title="<?php echo SWITCH_STATUS_WATCHED_LABEL; ?>" /></a>
<a id="linkStatus_<?php echo $data["idMovie"]; ?>_watched" onclick="changeStatus('toUnwatched', <?php echo $data["idMovie"]; ?>);" style="position:absolute;float:left;cursor:pointer;display:<?php echo ($playedStatus == "watched") ? "block" : "none"; ?>"><img id="buttonStatus_<?php echo $data["idMovie"]; ?>" src="images/watchedButton.png" title="<?php echo SWITCH_STATUS_UNWATCHED_LABEL; ?>" /></a>

<?php } ?>
<?php
$youtubeID = extractYoutubeId($data["movieToutube"]);
if(!empty($youtubeID))
Expand Down Expand Up @@ -328,7 +383,7 @@ function getEntriesTvShow($sql){
<?php
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
?>
<img class="thumbStatus arrondiTopLeft"src="images/<?php echo $playedStatus; ?>.png" title="<?php echo $playedStatus; ?>" style="display:none;" />
<img class="thumbStatus arrondiTopLeft"src="images/<?php echo $playedStatus; ?>.png" title="<?php echo (($playedStatus === "watched") ? STATUS_WATCHED_LABEL : STATUS_UNWATCHED_LABEL ); ?>" style="display:none;" />
<?php
}
?>
Expand Down Expand Up @@ -445,7 +500,7 @@ function getDetailsEntryMovie($id){
$echo = "<div class='details-title'>" . $titleFR . " (" . $titleEN . ")</div>";
$echo .= "<img class='details-thumb arrondi' src='" . $thumbs[0] . "' onerror=\"this.src='images/thumb-onerror.jpg';\" />";
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS)))
$echo .= "<img class='thumbStatus arrondiTopLeft' src='images/" . $movieStatus . ".png' title='" . $movieStatus ."' /> ";
$echo .= "<img class='thumbStatus arrondiTopLeft' src='images/" . $movieStatus . ".png' title='" . (($movieStatus === "watched") ? STATUS_WATCHED_LABEL : STATUS_UNWATCHED_LABEL) ."' /> ";
$echo .= "<div class='details-details'><b>" . SYNOPSIS_LABEL . " : </b><br />" . $synopsis . "<br /><br />";
$echo .= " <b>" . YEAR_LABEL . " : </b><br />" . $year . "<br /><br />";
$echo .= " <b>" . GENRE_LABEL . " : </b><br />" . $genre . "<br /><br />";
Expand Down Expand Up @@ -554,7 +609,7 @@ function getDetailsEntryTvShow($id){
$thumbs[0] = "http://" . $thumbs[0];
$echo .= " <img class='tvshow-details-season-thumb arrondi' src='" . $thumbs[0] . "' onerror=\"this.src='images/thumb-onerror.jpg';\" />";
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
$echo .= " <img class='thumbStatusSeason' src='images/" . $seasonStatus . "Season.png' title='" . $seasonStatus . "' />";
$echo .= " <img class='thumbStatusSeason' src='images/" . $seasonStatus . "Season.png' title='" . (($seasonStatus === "watched") ? STATUS_WATCHED_LABEL : STATUS_UNWATCHED_LABEL) . "' />";
}
$echo .= " <div class='tvshow-details-season-details-infos'>";
$echo .= " <div class='text-up bold size125'>" . SEASON_LABEL . " ".$data["seasonIdseason"]."</div>";
Expand Down Expand Up @@ -608,8 +663,10 @@ function getDetailsEntryTvShow($id){
$echo .= " <a onclick=\"toggleTvshowContent('tvshow-details-season-episode-synopsis', '".$data["idEpisode"]."');\" style=\"cursor:pointer;float:right;\"><img src='images/info.png' title='" . DESCRIPTION_LABEL . "' /></a>";
if(ENABLE_DOWNLOAD)
$echo .= " <a target='_blank' style=\"cursor:pointer;float:right;\" href='dl.php?type=tvshow&id=" . $data["idEpisode"] . "'><img src='images/download.png' title='" . DOWNLOAD_LABEL . "' /></a>";
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS)))
$echo .= " <a style=\"cursor:pointer;float:right;\" href='#'><img src='images/" . $episodeStatus . "Episode.png' title='" . $episodeStatus . "' /></a>";
if(WATCHED_STATUS_FOR_ALL || (ENABLE_AUTHENTICATION && in_array($_SESSION['user'], $WATCH_STATUS_FOR_USERS))){
$echo .= " <a id=\"linkStatus_" . $data["idEpisode"] . "_watched\" onclick=\"changeStatusTvShow('toUnwatched', " . $data["idEpisode"] . ");\" style=\"cursor:pointer;float:right;display:" . (($episodeStatus === "watched") ? "visible" : "none") . "\"><img src='images/watchedButton.png' title='" . STATUS_WATCHED_LABEL . "' /></a>";
$echo .= " <a id=\"linkStatus_" . $data["idEpisode"] . "_unwatched\" onclick=\"changeStatusTvShow('toWatched', " . $data["idEpisode"] . ");\" style=\"cursor:pointer;float:right;display:" . (($episodeStatus === "unwatched") ? "visible" : "none") . "\"><img src='images/unwatchedButton.png' title='" . STATUS_UNWATCHED_LABEL . "' /></a>";
}
$echo .= " <p class='tvshow-details-season-episode-synopsis' id='tvshow-details-season-episode-synopsis-".$data["idEpisode"]."'>";
$echo .= $data["episodeSynopsis"];
$echo .= " <br /><br />";
Expand Down
4 changes: 4 additions & 0 deletions i18n/lang_de.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
define("SEARCH_LABEL", "Suche");
define("RESET_LABEL", "Zurücksetzten");
define("NORESULT_LABEL", "Ende der Ergebnisse");
define("STATUS_WATCHED_LABEL", "Gesehen");
define("STATUS_UNWATCHED_LABEL", "Nicht gesehen");
define("SWITCH_STATUS_WATCHED_LABEL", "Setzen Sie diesen Film gesehen.");
define("SWITCH_STATUS_UNWATCHED_LABEL", "Setzen Sie diesen Film nicht gesehen.");

define("AUTHENTICATION_PAGE_TITLE", "Authentication page");
define("AUTHENTICATION_USER_PLACEHOLDER", "Benutzer");
Expand Down
4 changes: 4 additions & 0 deletions i18n/lang_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
define("SEARCH_LABEL", "Search");
define("RESET_LABEL", "Reset");
define("NORESULT_LABEL", "End of results");
define("STATUS_WATCHED_LABEL", "Watched");
define("STATUS_UNWATCHED_LABEL", "Unwatched");
define("SWITCH_STATUS_WATCHED_LABEL", "Switch to 'watched'");
define("SWITCH_STATUS_UNWATCHED_LABEL", "Switch to 'unwatched'");

define("AUTHENTICATION_PAGE_TITLE", "Authentication page");
define("AUTHENTICATION_USER_PLACEHOLDER", "Username");
Expand Down
4 changes: 4 additions & 0 deletions i18n/lang_es.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
define("SEARCH_LABEL", "Buscar");
define("RESET_LABEL", "Reajustar");
define("NORESULT_LABEL", "Fin de resultados");
define("STATUS_WATCHED_LABEL", "Vista");
define("STATUS_UNWATCHED_LABEL", "No vista");
define("SWITCH_STATUS_WATCHED_LABEL", "Pon esta película 'vista'");
define("SWITCH_STATUS_UNWATCHED_LABEL", "Pon esta película 'no vista'");

define("AUTHENTICATION_PAGE_TITLE", "Página de autenticación");
define("AUTHENTICATION_USER_PLACEHOLDER", "Nombre del usuario");
Expand Down
4 changes: 4 additions & 0 deletions i18n/lang_fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
define("SEARCH_LABEL", "Rechercher");
define("RESET_LABEL", "Réinitialiser");
define("NORESULT_LABEL", "Fin des résultats");
define("STATUS_WATCHED_LABEL", "Vu");
define("STATUS_UNWATCHED_LABEL", "Non-vu");
define("SWITCH_STATUS_WATCHED_LABEL", "Passer ce média comme 'vu'");
define("SWITCH_STATUS_UNWATCHED_LABEL", "Passer ce média comme 'non-vu'");

define("AUTHENTICATION_PAGE_TITLE", "Page d'authentification");
define("AUTHENTICATION_USER_PLACEHOLDER", "Nom d'utilisateur");
Expand Down
File renamed without changes
File renamed without changes
8 changes: 8 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
exit;
}

if(isset($_GET["id"]) && isset($_GET["action"]) && ($_GET["action"] === "toWatched" || $_GET["action"] === "toUnwatched")){
$id = intval($_GET["id"]);
$toStatus = strval($_GET["action"]);
if($id > 0)
changeStatusMovie($id, $toStatus);
exit;
}

if(isset($_GET["id"]) && isset($_GET["action"]) && $_GET["action"] == "detail"){
$id = intval($_GET["id"]);
if($id > 0)
Expand Down
48 changes: 48 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,54 @@ function printDetails(divDetails, id){
$("#"+divDetails).slideToggle();
}

function changeStatus(toStatus, id){
loc = document.location + "";
if(loc.indexOf("?") == -1)
loc += "?";

$.ajax({
    url : loc + "&action=" + toStatus + "&id=" + id,
    type: "GET",
success: function(data, textStatus, jqXHR){
if(toStatus == "toWatched"){
$("#cornerStatus_" + id + "_unwatched").fadeOut();
$("#cornerStatus_" + id + "_watched").fadeIn();
$("#linkStatus_" + id + "_unwatched").fadeOut().css("display","none");
$("#linkStatus_" + id + "_watched").fadeIn().css("display","block");
} else {
$("#cornerStatus_" + id + "_unwatched").fadeIn();
$("#cornerStatus_" + id + "_watched").fadeOut();
$("#linkStatus_" + id + "_unwatched").fadeIn().css("display","block");
$("#linkStatus_" + id + "_watched").fadeOut().css("display","none");
}
    },
    error: function (jqXHR, textStatus, errorThrown){
    }
});
}

function changeStatusTvShow(toStatus, id){
loc = document.location + "";
if(loc.indexOf("?") == -1)
loc += "?";

$.ajax({
    url : loc + "&action=" + toStatus + "&id=" + id,
    type: "GET",
success: function(data, textStatus, jqXHR){
if(toStatus == "toWatched"){
$("#linkStatus_" + id + "_unwatched").fadeOut().css("display","none");
$("#linkStatus_" + id + "_watched").fadeIn().css("display","block");
} else {
$("#linkStatus_" + id + "_unwatched").fadeIn().css("display","block");
$("#linkStatus_" + id + "_watched").fadeOut().css("display","none");
}
    },
    error: function (jqXHR, textStatus, errorThrown){
    }
});
}

function displayYoutube(divYoutube, idvideo){
// Set the height of opacity div to full page
$("#opacity").height($(document).height());
Expand Down
8 changes: 8 additions & 0 deletions tvshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
FROM " . NAX_TVSHOW_VIEW . " ORDER BY dateAdded DESC LIMIT $offset," . DEFAULT_ENTRIES_DISPLAY . ";";
}

if(isset($_GET["id"]) && isset($_GET["action"]) && ($_GET["action"] === "toWatched" || $_GET["action"] === "toUnwatched")){
$id = intval($_GET["id"]);
$toStatus = strval($_GET["action"]);
if($id > 0)
changeStatusEpisode($id, $toStatus);
exit;
}

if(isset($_GET["id"]) && isset($_GET["action"]) && $_GET["action"] == "detail"){
$id = intval($_GET["id"]);
if($id > 0)
Expand Down

0 comments on commit 8b7c10e

Please sign in to comment.