From bdcf99e585e815d924dc38c0ae4e4a86d81a704b Mon Sep 17 00:00:00 2001 From: Sebastien Plante Date: Sat, 1 Dec 2018 15:12:37 -0500 Subject: [PATCH] Added the function to change the thumbnail URL when clinking on the image. --- class.php | 18 ++++++++++ index.php | 87 ++++++++-------------------------------------- page.php | 75 +++++++++++++++++++++++++++++++++++++++ post.php | 12 +++++++ readme.md | 1 - style.css | 15 ++++++++ updatethumbnail.js | 41 ++++++++++++++++++++++ 7 files changed, 176 insertions(+), 73 deletions(-) create mode 100644 page.php create mode 100644 post.php create mode 100644 updatethumbnail.js diff --git a/class.php b/class.php index 4f3698f..b317661 100644 --- a/class.php +++ b/class.php @@ -78,6 +78,24 @@ class ps4 { return $url; } + function thumbnailupdateurl($gameid,$gamename,$url) { + $actualurl = $this->thumbnailurl($gameid); + if ($actualurl == "no-thumbnail.png") { + $sql = "INSERT INTO game_thumbnail (game_id, thumbnail_url) VALUES ('".$gameid."', '".$url."');"; + } else { + $sql = "UPDATE game_thumbnail SET thumbnail_url = '".$url."' WHERE game_id = '".$gameid."';"; + } + + $result = $this->mysql_conn($sql); + if ($result == 1) { + echo "SUCCESS: Updated image URL for ". $gamename ." (". $gameid .")"; + echo "

"; + } else { + echo "ERROR: Can't update image URL for ". $gamename ." (". $gameid .")"; + echo "

"; + } + } + } ?> \ No newline at end of file diff --git a/index.php b/index.php index cdf388e..9a430de 100644 --- a/index.php +++ b/index.php @@ -4,87 +4,30 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -include_once("class.php"); +?> -$ps4 = new ps4(); - -$sql = "SELECT * FROM game_time"; -$result = $ps4->mysql_conn($sql); - -echo " - + + + + -"; - -echo "Last Updated : ". date(DATE_RFC2822) ."

"; - -if ($result->num_rows > 0) { - // output data of each row - - while ($row = $result->fetch_assoc()) { - $games[$row["game_id"]]["game_id"] = $row["game_id"]; - $games[$row["game_id"]]["game_name"] = $row["game_name"]; - isset($games[$row["game_id"]]["game_total_time"]) ?: $games[$row["game_id"]]["game_total_time"] = 0; + - isset($games[$row["game_id"]]["game_played_first"]) ?: $games[$row["game_id"]]["game_played_first"] = $row["game_start"]; - isset($games[$row["game_id"]]["game_played_last"]) ?: $games[$row["game_id"]]["game_played_last"] = $row["game_end"]; - if ($row["game_start"] < $games[$row["game_id"]]["game_played_first"]) { - $games[$row["game_id"]]["game_played_first"] = $row["game_start"]; - } +
+ +
+ + - if ($row["game_end"] == "") { - $games[$row["game_id"]]["game_time"][$row["id"]] = -1; - $games[$row["game_id"]]["game_played_last"] = -1; - $games[$row["game_id"]]["game_total_time"] += ((round(microtime(true) * 1000)-$row["game_start"])/1000); - } else { - $games[$row["game_id"]]["game_time"][$row["id"]] = (($row["game_end"]-$row["game_start"])/1000); - $games[$row["game_id"]]["game_total_time"] += (($row["game_end"]-$row["game_start"])/1000); - if (($row["game_end"] > $games[$row["game_id"]]["game_played_last"]) AND ($games[$row["game_id"]]["game_played_last"] != -1)) { - $games[$row["game_id"]]["game_played_last"] = $row["game_end"]; - } - } - } - -$currentid = ""; -foreach ($games as $key => $value) { - echo "
"; - echo "
"; - echo "thumbnailurl($key)."\" border=0 weight=\"80px\" height=\"80px\">"; - echo "
"; - echo "
"; - echo "". $games[$key]["game_name"] ." (". $games[$key]["game_id"] .")"; - echo "
"; - echo "Total Time Played : ". $ps4->playtime($games[$key]["game_total_time"],true) .""; - echo "
First Played on : ". $ps4->secondsToDate($games[$key]["game_played_first"]); - echo "
Last Played on : "; - - if ($games[$key]["game_played_last"] == -1) { - echo "now playing"; - } else { - echo $ps4->secondsToDate($games[$key]["game_played_last"]); - } - echo "
"; // info - echo "
"; // game -} - -/* -echo "
";
-print_r($games);
-echo "
"; -*/ - -} else { - echo "0 results"; -} - -echo " -"; -?> diff --git a/page.php b/page.php new file mode 100644 index 0000000..249e7cd --- /dev/null +++ b/page.php @@ -0,0 +1,75 @@ +mysql_conn($sql); +?> + +Last Updated :

+ +num_rows > 0) { + // output data of each row + + while ($row = $result->fetch_assoc()) { + + + $games[$row["game_id"]]["game_id"] = $row["game_id"]; + $games[$row["game_id"]]["game_name"] = $row["game_name"]; + isset($games[$row["game_id"]]["game_total_time"]) ?: $games[$row["game_id"]]["game_total_time"] = 0; + + isset($games[$row["game_id"]]["game_played_first"]) ?: $games[$row["game_id"]]["game_played_first"] = $row["game_start"]; + isset($games[$row["game_id"]]["game_played_last"]) ?: $games[$row["game_id"]]["game_played_last"] = $row["game_end"]; + if ($row["game_start"] < $games[$row["game_id"]]["game_played_first"]) { + $games[$row["game_id"]]["game_played_first"] = $row["game_start"]; + } + + if ($row["game_end"] == "") { + $games[$row["game_id"]]["game_time"][$row["id"]] = -1; + $games[$row["game_id"]]["game_played_last"] = -1; + $games[$row["game_id"]]["game_total_time"] += ((round(microtime(true) * 1000)-$row["game_start"])/1000); + } else { + $games[$row["game_id"]]["game_time"][$row["id"]] = (($row["game_end"]-$row["game_start"])/1000); + $games[$row["game_id"]]["game_total_time"] += (($row["game_end"]-$row["game_start"])/1000); + if (($row["game_end"] > $games[$row["game_id"]]["game_played_last"]) AND ($games[$row["game_id"]]["game_played_last"] != -1)) { + $games[$row["game_id"]]["game_played_last"] = $row["game_end"]; + } + } + } + +$currentid = ""; +foreach ($games as $key => $value) { + echo "
"; + echo "
"; + echo "thumbnailurl($key)."\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('". $games[$key]["game_id"] ."', '". $games[$key]["game_name"] ."');\">"; + echo "
"; + echo "
"; + echo "". $games[$key]["game_name"] ." (". $games[$key]["game_id"] .")"; + echo "
"; + echo "Total Time Played : ". $ps4->playtime($games[$key]["game_total_time"],true) .""; + echo "
First Played on : ". $ps4->secondsToDate($games[$key]["game_played_first"]); + echo "
Last Played on : "; + + if ($games[$key]["game_played_last"] == -1) { + echo "now playing"; + } else { + echo $ps4->secondsToDate($games[$key]["game_played_last"]); + } + echo "
"; // info + echo "
"; // game +} + +/* +echo "
";
+print_r($games);
+echo "
"; +*/ + +} else { + echo "0 results"; +} + +?> + diff --git a/post.php b/post.php new file mode 100644 index 0000000..6bdde2f --- /dev/null +++ b/post.php @@ -0,0 +1,12 @@ +thumbnailupdateurl($_POST['gameid'],$_POST['gamename'],$_POST['url']); + } + } +?> \ No newline at end of file diff --git a/readme.md b/readme.md index 4c81ae1..d47d3dc 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,5 @@ ## To do - ajouter les informations sur les tables MySQL - populer le details -- crée la fonction pour set thumbnail - ordre d'affichage? - crée le viewport pour le display sur les mobiles. \ No newline at end of file diff --git a/style.css b/style.css index da18ab1..212ed48 100644 --- a/style.css +++ b/style.css @@ -29,4 +29,19 @@ body{ border: 1px solid #027c84; border-radius: 2px; margin-bottom: 10px; +} + +#message { + + margin: 0px; + padding: 0px; + width: 100%; + height: 100%; + +} + +#message { + + margin-bottom: 5px; + } \ No newline at end of file diff --git a/updatethumbnail.js b/updatethumbnail.js new file mode 100644 index 0000000..addb0d7 --- /dev/null +++ b/updatethumbnail.js @@ -0,0 +1,41 @@ +function thumbnailupdateurl(gameid, gamename) { + + var sql; + + var url = prompt("Enter Image URL for " + gamename + " (" + gameid + ")", ""); + + if (url == "") { + + alert ("Enter something !"); + + } else { + + var data = { + 'what': 'thumbnail', + 'gameid': gameid, + 'gamename': gamename, + 'url': url + }; + + + $.ajax( + { + type: "POST", + url: "post.php", + data: data, + success: function(data, textStatus, jqXHR) + { + $( document ).ready(function(){ + $('#message').html(data); + $('#message').fadeIn('slow', function(){ + $('#message').delay(3000).fadeOut(); + }); + $("#page").load('page.php'); + }); + + } + }); + + } + +} \ No newline at end of file