BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

token_history.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * User token history page
  5. * This page lists the torrents a user has spent his tokens on.
  6. * It gets called if $_GET['action'] === 'token_history.'
  7. *
  8. * Using $_GET['userid'] allows a mod to see any user's token history.
  9. * Non-mods and empty userid show $LoggedUser['ID']'s history.
  10. */
  11. # Validate user ID
  12. if (isset($_GET['userid'])) {
  13. $UserID = $_GET['userid'];
  14. } else {
  15. $UserID = $LoggedUser['ID'];
  16. }
  17. Security::checkInt($UserID);
  18. # Get user info
  19. $UserInfo = Users::user_info($UserID);
  20. $Perms = Permissions::get_permissions($UserInfo['PermissionID']);
  21. $UserClass = $Perms['Class'];
  22. # Validate mod permissions
  23. if (!check_perms('users_mod')) {
  24. if ($LoggedUser['ID'] !== $UserID && !check_paranoia(false, $User['Paranoia'], $UserClass, $UserID)) {
  25. error(403);
  26. }
  27. }
  28. if (isset($_GET['expire'])) {
  29. if (!check_perms('users_mod')) {
  30. error(403);
  31. }
  32. $UserID = $_GET['userid'];
  33. $TorrentID = $_GET['torrentid'];
  34. if (!is_number($UserID) || !is_number($TorrentID)) {
  35. error(403);
  36. }
  37. $DB->query("
  38. SELECT
  39. HEX(`info_hash`)
  40. FROM
  41. `torrents`
  42. WHERE
  43. `ID` = '$TorrentID'
  44. ");
  45. if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, false)) {
  46. $DB->query("
  47. UPDATE
  48. `users_freeleeches`
  49. SET
  50. `Expired` = TRUE
  51. WHERE
  52. `UserID` = '$UserID' AND `TorrentID` = '$TorrentID'
  53. ");
  54. $Cache->delete_value("users_tokens_$UserID");
  55. Tracker::update_tracker(
  56. 'remove_token',
  57. ['info_hash' => substr('%'.chunk_split($InfoHash, 2, '%'), 0, -1), 'userid' => $UserID]
  58. );
  59. }
  60. header("Location: userhistory.php?action=token_history&userid=$UserID");
  61. }
  62. # Render HTML
  63. View::show_header('Freeleech token history');
  64. list($Page, $Limit) = Format::page_limit(25);
  65. $DB->query("
  66. SELECT SQL_CALC_FOUND_ROWS
  67. f.`TorrentID`,
  68. t.`GroupID`,
  69. f.`Time`,
  70. f.`Expired`,
  71. f.`Downloaded`,
  72. f.`Uses`,
  73. g.`title`
  74. FROM
  75. `users_freeleeches` AS f
  76. JOIN `torrents` AS t
  77. ON
  78. t.`ID` = f.`TorrentID`
  79. JOIN `torrents_group` AS g
  80. ON
  81. g.`id` = t.`GroupID`
  82. WHERE
  83. f.`UserID` = '$UserID'
  84. ORDER BY
  85. f.`Time`
  86. DESC
  87. LIMIT $Limit
  88. ");
  89. $Tokens = $DB->to_array();
  90. $DB->query('SELECT FOUND_ROWS()');
  91. list($NumResults) = $DB->next_record();
  92. $Pages = Format::get_pages($Page, $NumResults, 25);
  93. ?>
  94. <div class="header">
  95. <h2>
  96. Freeleech token history for
  97. <?= Users::format_username($UserID, false, false, false) ?>
  98. </h2>
  99. </div>
  100. <div class="linkbox">
  101. <?= $Pages ?>
  102. </div>
  103. <table>
  104. <tr class="colhead_dark">
  105. <th>Torrent</th>
  106. <th>Time</th>
  107. <th>Expired</th>
  108. <?php if (check_perms('users_mod')) { ?>
  109. <th>Downloaded</th>
  110. <th>Tokens used</th>
  111. <?php } ?>
  112. </tr>
  113. <?php
  114. foreach ($Tokens as $Token) {
  115. $GroupIDs[] = $Token['GroupID'];
  116. }
  117. $Artists = Artists::get_artists($GroupIDs);
  118. foreach ($Tokens as $Token) {
  119. list($TorrentID, $GroupID, $Time, $Expired, $Downloaded, $Uses, $Name) = $Token;
  120. if ($Name !== '') {
  121. $Name = "<a href='torrents.php?torrentid=$TorrentID'>$Name</a>";
  122. } else {
  123. $Name = "(<i>Deleted torrent <a href='log.php?search=Torrent+$TorrentID'>$TorrentID</a></i>)";
  124. }
  125. $ArtistName = Artists::display_artists($Artists[$GroupID]);
  126. if ($ArtistName) {
  127. $Name = $ArtistName.$Name;
  128. } ?>
  129. <tr class="row">
  130. <td>
  131. <?= $Name ?>
  132. </td>
  133. <td>
  134. <?= time_diff($Time) ?>
  135. </td>
  136. <td>
  137. <?= ($Expired ? 'Yes' : 'No') ?>
  138. <?= (check_perms('users_mod') && !$Expired)
  139. ? " <a href='userhistory.php?action=token_history&amp;expire=1&amp;userid=$UserID&amp;torrentid=$TorrentID'>(expire)</a>"
  140. : ''; ?>
  141. </td>
  142. <?php if (check_perms('users_mod')) { ?>
  143. <td>
  144. <?= Format::get_size($Downloaded) ?>
  145. </td>
  146. <td>
  147. <?= $Uses ?>
  148. </td>
  149. <?php } ?>
  150. </tr>
  151. <?php
  152. } ?>
  153. </table>
  154. <div class="linkbox">
  155. <?= $Pages ?>
  156. </div>
  157. <?php View::show_footer();