From a63b8d217b936ab6954e227aaa8a3e966cf1f1d2 Mon Sep 17 00:00:00 2001 From: Mahmood - Zer0xFF <5013823+Zer0xFF@users.noreply.github.com> Date: Fri, 7 Sep 2018 10:15:40 +0100 Subject: [PATCH] basic duplicate reporting system --- include/TGDB.API.php | 79 +++++++ website/actions/report_game.php | 61 ++++++ website/actions/resolve_game_report.php | 47 +++++ website/game.php | 33 ++- website/report_review.php | 266 ++++++++++++++++++++++++ 5 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 website/actions/report_game.php create mode 100644 website/actions/resolve_game_report.php create mode 100644 website/report_review.php diff --git a/include/TGDB.API.php b/include/TGDB.API.php index e50af93..c66e53c 100644 --- a/include/TGDB.API.php +++ b/include/TGDB.API.php @@ -2044,6 +2044,85 @@ function InsertGame($user_id, $game_title, $overview, $youtube, $release_date, $ } return $game_id; } + + function GetGamesReports($is_resolved, $offset = 0, $limit = 20) + { + $qry = "SELECT games_reports.*, games.game_title, games.platform FROM games_reports left join games on games_reports.games_id = games.id where games_reports.is_resolved = :is_resolved LIMIT :limit OFFSET :offset;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + $sth->bindValue(':is_resolved', $is_resolved, PDO::PARAM_INT); + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } + + function ReportGame($user_id, $username, $REQUEST) + { + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $REQUEST['game_id'], PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return -1; + } + } + if($REQUEST['report_type'] == 1) + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $REQUEST['metadata_0'], PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return -2; + } + } + + $qry = "INSERT INTO games_reports (user_id, username, games_id, type, metadata_0, extra, is_resolved) values (:user_id, :username, :games_id, :type, :metadata_0, :extra, 0)"; + + $sth = $dbh->prepare($qry); + + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':username', $username, PDO::PARAM_STR); + + $sth->bindValue(':games_id', $REQUEST['game_id'], PDO::PARAM_INT); + + $sth->bindValue(':type', $REQUEST['report_type'], PDO::PARAM_INT); + $sth->bindValue(':metadata_0', !empty($REQUEST['metadata_0']) ? $REQUEST['metadata_0'] : null, PDO::PARAM_STR); + $sth->bindValue(':extra', !empty($REQUEST['extra']) ? $REQUEST['extra'] : null, PDO::PARAM_STR); + + return $sth->execute(); + } + + function ResolveGameReport($user_id, $username, $id) + { + $qry = "UPDATE games_reports SET is_resolved = 1, resolver_user_id=:user_id, resolver_username=:username WHERE id=:id;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + $sth->bindValue(':id', $id, PDO::PARAM_INT); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':username', $username, PDO::PARAM_STR); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } } ?> diff --git a/website/actions/report_game.php b/website/actions/report_game.php new file mode 100644 index 0000000..484185c --- /dev/null +++ b/website/actions/report_game.php @@ -0,0 +1,61 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} + +$RequiredReportArrayFields = ['game_id', 'report_type', 'metadata_0']; + +foreach($RequiredReportArrayFields as $field) +{ + if(!isset($_REQUEST[$field]) || empty($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . " ($field)"); + } +} + +//TODO: need a better check should we add different types +if($_REQUEST['report_type'] != 1) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_INVALID_PARAM_ERROR . " (report_type)"); +} +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->ReportGame($_user->GetUserID(), $_user->GetUsername(), $_REQUEST); + + switch((integer) $res) + { + case -2: + $msg = "Original game does not exist."; + break; + case -1: + $msg = "Reported game does not exist."; + break; + case 1: + $msg = "Thank You For The Report."; + break; + } + returnJSONAndDie($res, $msg . "($res)"); + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); + + diff --git a/website/actions/resolve_game_report.php b/website/actions/resolve_game_report.php new file mode 100644 index 0000000..172ee02 --- /dev/null +++ b/website/actions/resolve_game_report.php @@ -0,0 +1,47 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('m_delete_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + +if(!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + + + $res = $API->ResolveGameReport($_user->GetUserID(), $_user->GetUsername(), $_REQUEST['id']); + + returnJSONAndDie(1, "success!!"); + + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/game.php b/website/game.php index 37af747..2d7f3ad 100755 --- a/website/game.php +++ b/website/game.php @@ -99,6 +99,36 @@ }; $('[data-fancybox]').fancybox(fancyboxOpts); + $('#reportbtn').click(function() + { + isLoggedIn()) : ?> + var game_id = parseInt(prompt("Please enter the original game id", "")); + if(isNaN(game_id)) + { + alert('Invalid game id.') + return; + } + $(this).append(''); + $(this).attr("disabled", true); + $.ajax({ + method: "POST", + url: "/actions/report_game.php", + data: { + game_id: id ?>, + report_type:1, + metadata_0: game_id, + } + }) + .done(function( msg ) { + $('#reportbtn').attr("disabled", false); + $('#reportbtn').find('.fa').remove(); + var response = JSON.parse(msg); + alert(msg); + }); + + alert("You must login to use this feature."); + + }); $('[data-toggle="bookmark"]').click(function() { @@ -399,7 +429,8 @@ Control Panel
-

id][$Game->game_title]") ?>" class="btn btn-primary btn-block">Report

+

+

Edit

diff --git a/website/report_review.php b/website/report_review.php new file mode 100644 index 0000000..fd87663 --- /dev/null +++ b/website/report_review.php @@ -0,0 +1,266 @@ +isLoggedIn()) +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); + $errorPage->print_die(); +} +else +{ + if(!$_user->hasPermission('m_delete_games')) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + $errorPage->print_die(); + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/include/WebUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + +$BASE_URL = CommonUtils::getImagesBaseURL(); + +$API = TGDB::getInstance(); +$reports = $API->GetGamesReports(0); +foreach($reports as $Game) +{ + $IDs[] = $Game->games_id; + if($Game->type == 1) + { + $additional_games_id[] = $Game->metadata_0; + } + $PlatformIDs[] = $Game->platform; +} +if(isset($additional_games_id)) +{ + $additional_games = $API->GetGameByID($additional_games_id); +} +if(isset($IDs)) +{ + $games = $API->GetGameByID($IDs); +} + +foreach($additional_games as $Game) +{ + $IDs[] = $Game->id; + $PlatformIDs[] = $Game->platform; +} +$Platforms = $API->GetPlatforms($PlatformIDs); +$covers = $API->GetGameBoxartByID($IDs, 0, 9999); +foreach($reports as $Game) +{ + if(isset($covers[$Game->games_id])) + { + $Game->boxart = $covers[$Game->games_id]; + } +} + +foreach($additional_games as &$Game) +{ + $ref_additional_games[$Game->id] = $Game; + if(isset($covers[$Game->id])) + { + $Game->boxart = $covers[$Game->id]; + } +} +foreach($games as &$Game) +{ + $ref_games[$Game->id] = $Game; +} + +$Game = null; + +function PrintViews(&$report) +{ + switch($report->type) + { + case 1: + PrintDuplicateView($report); + break; + } +} + +function PrintDuplicateView(&$report) +{ global $ref_additional_games, $ref_games, $Platforms; + if(!isset($ref_additional_games[$report->metadata_0]) || !isset($ref_games[$report->games_id])) + { + //TODO: mark as resolved + return; + } + ?> +
+
+
+ + + +
+
+
+ username ?> reports the following game +
+ game_title . "(games_id: $report->games_id)" ?> +
as a duplicate of
+ metadata_0]->game_title . " (games_id: $report->metadata_0)" ?> +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ + + +
+
+ +
+
+
game_title ?>
+

Platform: platform]->name ?>

+
+
+
+
+
metadata_0]->game_title ?>
+

Platform: metadata_0]->platform]->name ?>

+
+
+
+
+ setTitle("TGDB - Games Reports"); +$Header->appendRawHeader(function() { ?> + + + +print(); ?> + +
+
+ +
+

Reports


+
+ +
+ +
+ +