Gazelle/sections/reportsv2/ajax_create_report.php

89 lines
1.9 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/*
* This page is for creating a report using AJAX.
* It should have the following posted fields:
* [auth] => AUTH_KEY
* [torrentid] => TORRENT_ID
* [type] => TYPE
* [otherid] => OTHER_ID
*
* It should not be used on site as is, except in its current use (Switch) as it is lacking for any purpose but this.
*/
2013-05-04 08:00:48 +00:00
if (!check_perms('admin_reports')) {
2011-03-28 14:21:28 +00:00
error(403);
}
authorize();
2013-05-04 08:00:48 +00:00
if (!is_number($_POST['torrentid'])) {
2011-03-28 14:21:28 +00:00
echo 'No Torrent ID';
die();
} else {
$TorrentID = $_POST['torrentid'];
}
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT tg.CategoryID
FROM torrents_group AS tg
JOIN torrents AS t ON t.GroupID=tg.ID
WHERE t.ID = ".$TorrentID);
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-05-04 08:00:48 +00:00
$Err = 'No torrent with that ID exists!';
2011-03-28 14:21:28 +00:00
} else {
list($CategoryID) = $DB->next_record();
}
2013-05-04 08:00:48 +00:00
if (!isset($_POST['type'])) {
2011-03-28 14:21:28 +00:00
echo 'Missing Type';
die();
} else if (array_key_exists($_POST['type'], $Types[$CategoryID])) {
$Type = $_POST['type'];
$ReportType = $Types[$CategoryID][$Type];
2013-05-04 08:00:48 +00:00
} else if (array_key_exists($_POST['type'],$Types['master'])) {
2011-03-28 14:21:28 +00:00
$Type = $_POST['type'];
$ReportType = $Types['master'][$Type];
} else {
//There was a type but it wasn't an option!
echo 'Wrong type';
die();
}
$ExtraID = $_POST['otherid'];
2013-05-04 08:00:48 +00:00
if (!empty($_POST['extra'])) {
2011-03-28 14:21:28 +00:00
$Extra = db_string($_POST['extra']);
} else {
2013-05-04 08:00:48 +00:00
$Extra = '';
2011-03-28 14:21:28 +00:00
}
2013-05-04 08:00:48 +00:00
if (!empty($Err)) {
2011-03-28 14:21:28 +00:00
echo $Err;
die();
}
2013-05-04 08:00:48 +00:00
$DB->query("
SELECT ID
FROM reportsv2
WHERE TorrentID=$TorrentID
AND ReporterID=".db_string($LoggedUser['ID'])."
AND ReportedTime > '".time_minus(3)."'");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2011-03-28 14:21:28 +00:00
die();
}
2013-05-27 08:00:58 +00:00
$DB->query("
INSERT INTO reportsv2
(ReporterID, TorrentID, Type, UserComment, Status, ReportedTime, ExtraID)
VALUES
(".db_string($LoggedUser['ID']).", $TorrentID, '$Type', '$Extra', 'New', '".sqltime()."', '$ExtraID')");
2011-03-28 14:21:28 +00:00
$ReportID = $DB->inserted_id();
$Cache->delete_value('reports_torrent_'.$TorrentID);
$Cache->increment('num_torrent_reportsv2');
echo $ReportID;
?>