123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- declare(strict_types=1);
-
- /**
- * 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.
- * Non-mods and empty userid show $LoggedUser['ID']'s history.
- */
-
- # Validate user ID
- if (isset($_GET['userid'])) {
- $UserID = $_GET['userid'];
- } else {
- $UserID = $LoggedUser['ID'];
- }
-
- Security::checkInt($UserID);
-
- # Get user info
- $UserInfo = Users::user_info($UserID);
- $Perms = Permissions::get_permissions($UserInfo['PermissionID']);
- $UserClass = $Perms['Class'];
-
- # Validate mod permissions
- if (!check_perms('users_mod')) {
- if ($LoggedUser['ID'] !== $UserID && !check_paranoia(false, $User['Paranoia'], $UserClass, $UserID)) {
- error(403);
- }
- }
-
- if (isset($_GET['expire'])) {
- if (!check_perms('users_mod')) {
- error(403);
- }
-
- $UserID = $_GET['userid'];
- $TorrentID = $_GET['torrentid'];
-
- if (!is_number($UserID) || !is_number($TorrentID)) {
- error(403);
- }
-
- $DB->query("
- SELECT
- HEX(`info_hash`)
- FROM
- `torrents`
- WHERE
- `ID` = '$TorrentID'
- ");
-
- if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, false)) {
- $DB->query("
- UPDATE
- `users_freeleeches`
- SET
- `Expired` = TRUE
- WHERE
- `UserID` = '$UserID' AND `TorrentID` = '$TorrentID'
- ");
-
- $Cache->delete_value("users_tokens_$UserID");
- Tracker::update_tracker(
- 'remove_token',
- ['info_hash' => substr('%'.chunk_split($InfoHash, 2, '%'), 0, -1), 'userid' => $UserID]
- );
- }
- header("Location: userhistory.php?action=token_history&userid=$UserID");
- }
-
- # Render HTML
- View::show_header('Freeleech token history');
- list($Page, $Limit) = Format::page_limit(25);
-
- $DB->query("
- SELECT SQL_CALC_FOUND_ROWS
- f.`TorrentID`,
- t.`GroupID`,
- f.`Time`,
- f.`Expired`,
- f.`Downloaded`,
- f.`Uses`,
- g.`title`
- 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
- ");
-
- $Tokens = $DB->to_array();
- $DB->query('SELECT FOUND_ROWS()');
- list($NumResults) = $DB->next_record();
- $Pages = Format::get_pages($Page, $NumResults, 25);
- ?>
-
- <div class="header">
- <h2>
- Freeleech token history for
- <?= Users::format_username($UserID, false, false, false) ?>
- </h2>
- </div>
-
- <div class="linkbox">
- <?= $Pages ?>
- </div>
-
- <table>
- <tr class="colhead_dark">
- <th>Torrent</th>
- <th>Time</th>
- <th>Expired</th>
-
- <?php if (check_perms('users_mod')) { ?>
- <th>Downloaded</th>
- <th>Tokens used</th>
- <?php } ?>
- </tr>
-
- <?php
- foreach ($Tokens as $Token) {
- $GroupIDs[] = $Token['GroupID'];
- }
- $Artists = Artists::get_artists($GroupIDs);
-
- foreach ($Tokens as $Token) {
- list($TorrentID, $GroupID, $Time, $Expired, $Downloaded, $Uses, $Name) = $Token;
-
- if ($Name !== '') {
- $Name = "<a href='torrents.php?torrentid=$TorrentID'>$Name</a>";
- } else {
- $Name = "(<i>Deleted torrent <a href='log.php?search=Torrent+$TorrentID'>$TorrentID</a></i>)";
- }
-
- $ArtistName = Artists::display_artists($Artists[$GroupID]);
- if ($ArtistName) {
- $Name = $ArtistName.$Name;
- } ?>
-
- <tr class="row">
- <td>
- <?= $Name ?>
- </td>
-
- <td>
- <?= time_diff($Time) ?>
- </td>
-
- <td>
- <?= ($Expired ? 'Yes' : 'No') ?>
- <?= (check_perms('users_mod') && !$Expired)
- ? " <a href='userhistory.php?action=token_history&expire=1&userid=$UserID&torrentid=$TorrentID'>(expire)</a>"
- : ''; ?>
- </td>
-
- <?php if (check_perms('users_mod')) { ?>
- <td>
- <?= Format::get_size($Downloaded) ?>
- </td>
-
- <td>
- <?= $Uses ?>
- </td>
- <?php } ?>
- </tr>
- <?php
- } ?>
- </table>
-
- <div class="linkbox">
- <?= $Pages ?>
- </div>
-
- <?php View::show_footer();
|