Skip to content

Commit

Permalink
basic duplicate reporting system
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0xFF committed Sep 7, 2018
1 parent b7674fe commit a63b8d2
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 1 deletion.
79 changes: 79 additions & 0 deletions include/TGDB.API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

?>
61 changes: 61 additions & 0 deletions website/actions/report_game.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
require_once __DIR__ . "/../include/ErrorPage.class.php";
require_once __DIR__ . "/../include/login.phpbb.class.php";

function returnJSONAndDie($code, $msg)
{
echo json_encode(array("code" => $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!!");


47 changes: 47 additions & 0 deletions website/actions/resolve_game_report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
require_once __DIR__ . "/../include/ErrorPage.class.php";
require_once __DIR__ . "/../include/login.phpbb.class.php";

function returnJSONAndDie($code, $msg)
{
echo json_encode(array("code" => $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!!");
33 changes: 32 additions & 1 deletion website/game.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@
};
$('[data-fancybox]').fancybox(fancyboxOpts);

$('#reportbtn').click(function()
{
<?php if ($_user->isLoggedIn()) : ?>
var game_id = parseInt(prompt("Please enter the original game id", ""));
if(isNaN(game_id))
{
alert('Invalid game id.')
return;
}
$(this).append('<i class="fa fa-spinner fa-pulse"></i>');
$(this).attr("disabled", true);
$.ajax({
method: "POST",
url: "/actions/report_game.php",
data: {
game_id: <?= $Game->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);
});
<?php else : ?>
alert("You must login to use this feature.");
<?php endif; ?>
});

$('[data-toggle="bookmark"]').click(function()
{
Expand Down Expand Up @@ -399,7 +429,8 @@
<legend>Control Panel</legend>
</div>
<div class="card-body">
<p><a href="https://forums.thegamesdb.net/memberlist.php?mode=contactadmin&subject=<?= urlencode("[REPORT][GAME:$Game->id][$Game->game_title]") ?>" class="btn btn-primary btn-block">Report</a></p>
<p><button id="reportbtn" class="btn btn-primary btn-block">Report Duplicate</button></p>
<!--<p><a href="https://forums.thegamesdb.net/memberlist.php?mode=contactadmin&subject=<?= urlencode("[REPORT][GAME:$Game->id][$Game->game_title]") ?>" class="btn btn-primary btn-block">Report</a></p>-->
<p><a href="/edit_game.php?id=<?= $Game->id ?>" class="btn btn-primary btn-block">Edit</a></p>
</div>
</div>
Expand Down
Loading

0 comments on commit a63b8d2

Please sign in to comment.