Gazelle/sections/userhistory/token_history.php

120 lines
3.5 KiB
PHP
Raw Normal View History

2011-10-08 08:00:14 +00:00
<?
/************************************************************************
||------------------|| User token history page ||-----------------------||
This page lists the torrents a user has spent his tokens on. It
gets called if $_GET['action'] == 'token_history'.
Using $_GET['userid'] allows a mod to see any user's token history.
Nonmods and empty userid show $LoggedUser['ID']'s history
************************************************************************/
if (isset($_GET['userid'])) {
2011-11-03 08:00:19 +00:00
$UserID = $_GET['userid'];
2011-10-08 08:00:14 +00:00
} else {
$UserID = $LoggedUser['ID'];
}
if (!is_number($UserID)) { error(404); }
2012-10-11 08:00:15 +00:00
$UserInfo = Users::user_info($UserID);
$Perms = Permissions::get_permissions($UserInfo['PermissionID']);
2011-11-03 08:00:19 +00:00
$UserClass = $Perms['Class'];
2012-08-12 08:00:16 +00:00
if(!check_perms('users_mod')) {
if($LoggedUser['ID'] != $UserID && !check_paranoia(false, $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-11-03 08:00:19 +00:00
}
2011-10-08 08:00:14 +00:00
if (isset($_GET['expire'])) {
if (!check_perms('users_mod')) { error(403); }
$UserID = $_GET['userid'];
$TorrentID = $_GET['torrentid'];
2013-02-22 08:00:24 +00:00
2011-10-08 08:00:14 +00:00
if (!is_number($UserID) || !is_number($TorrentID)) { error(403); }
$DB->query("SELECT info_hash FROM torrents where ID = $TorrentID");
if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, FALSE)) {
2011-10-08 08:00:14 +00:00
$DB->query("UPDATE users_freeleeches SET Expired=TRUE WHERE UserID=$UserID AND TorrentID=$TorrentID");
$Cache->delete_value('users_tokens_'.$UserID);
2012-10-11 08:00:15 +00:00
Tracker::update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID));
2011-10-08 08:00:14 +00:00
}
header("Location: userhistory.php?action=token_history&userid=$UserID");
}
2012-10-11 08:00:15 +00:00
View::show_header('Freeleech token history');
2011-10-08 08:00:14 +00:00
2012-10-11 08:00:15 +00:00
list($Page,$Limit) = Format::page_limit(25);
2011-10-08 08:00:14 +00:00
$DB->query("SELECT SQL_CALC_FOUND_ROWS
2013-02-07 08:00:47 +00:00
f.TorrentID,
t.GroupID,
f.Time,
f.Expired,
f.Downloaded,
f.Uses,
g.Name,
t.Format,
t.Encoding
2011-10-08 08:00:14 +00:00
FROM users_freeleeches AS f
JOIN torrents AS t ON t.ID = f.TorrentID
JOIN torrents_group AS g ON g.ID = t.GroupID
WHERE f.UserID = $UserID
ORDER BY f.Time DESC
LIMIT $Limit");
2011-10-29 08:00:15 +00:00
$Tokens = $DB->to_array();
$DB->query("SELECT FOUND_ROWS()");
list($NumResults) = $DB->next_record();
2012-10-11 08:00:15 +00:00
$Pages=Format::get_pages($Page, $NumResults, 25);
2011-10-29 08:00:15 +00:00
2011-10-08 08:00:14 +00:00
?>
2012-08-19 08:00:19 +00:00
<div class="header">
2012-10-29 08:00:20 +00:00
<h2>Freeleech token history for <?=Users::format_username($UserID, false, false, false)?></h2>
2012-08-19 08:00:19 +00:00
</div>
2011-10-08 08:00:14 +00:00
<div class="linkbox"><?=$Pages?></div>
<table>
<tr class="colhead_dark">
<td>Torrent</td>
<td>Time</td>
<td>Expired</td>
<? if (check_perms('users_mod')) { ?>
<td>Downloaded</td>
2011-11-04 08:00:18 +00:00
<td>Tokens Used</td>
2011-10-08 08:00:14 +00:00
<? } ?>
</tr>
<?
2011-10-30 08:00:11 +00:00
foreach ($Tokens as $Token) {
$GroupIDs[] = $Token['GroupID'];
}
2012-10-11 08:00:15 +00:00
$Artists = Artists::get_artists($GroupIDs);
2011-10-30 08:00:11 +00:00
2011-10-08 08:00:14 +00:00
$i = true;
foreach ($Tokens as $Token) {
$i = !$i;
2013-02-22 08:00:24 +00:00
list($TorrentID, $GroupID, $Time, $Expired, $Downloaded, $Uses, $Name, $Format, $Encoding) = $Token;
2011-10-30 08:00:11 +00:00
$Name = "<a href=\"torrents.php?torrentid=$TorrentID\">$Name</a>";
2012-10-11 08:00:15 +00:00
$ArtistName = Artists::display_artists($Artists[$GroupID]);
2011-10-08 08:00:14 +00:00
if($ArtistName) {
2011-10-30 08:00:11 +00:00
$Name = $ArtistName.$Name;
2011-10-08 08:00:14 +00:00
}
if($Format && $Encoding) {
$Name.=' ['.$Format.' / '.$Encoding.']';
}
?>
<tr class="<?=($i?'rowa':'rowb')?>">
<td><?=$Name?></td>
<td><?=time_diff($Time)?></td>
2012-09-09 08:00:26 +00:00
<td><?=($Expired ? 'Yes' : 'No')?><?=(check_perms('users_mod') && !$Expired)?" <a href=\"userhistory.php?action=token_history&amp;expire=1&amp;userid=$UserID&amp;torrentid=$TorrentID\">(expire)</a>":''?>
2011-10-08 08:00:14 +00:00
</td>
<? if (check_perms('users_mod')) { ?>
2012-10-11 08:00:15 +00:00
<td><?=Format::get_size($Downloaded)?></td>
2011-11-04 08:00:18 +00:00
<td><?=$Uses?></td>
2011-10-08 08:00:14 +00:00
<? } ?>
</tr>
<? }
?>
</table>
<div class="linkbox"><?=$Pages?></div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2012-08-12 08:00:16 +00:00
?>