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 4.0KB

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. Security::checkInt($UserID, $TorrentID);
  35. $DB->prepare_query("
  36. SELECT
  37. HEX(`info_hash`)
  38. FROM
  39. `torrents`
  40. WHERE
  41. `ID` = '$TorrentID'
  42. ");
  43. $DB->exec_prepared_query();
  44. if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, false)) {
  45. $DB->prepare_query("
  46. UPDATE
  47. `users_freeleeches`
  48. SET
  49. `Expired` = TRUE
  50. WHERE
  51. `UserID` = '$UserID' AND `TorrentID` = '$TorrentID'
  52. ");
  53. $DB->exec_prepared_query();
  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->prepare_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. $DB->exec_prepared_query();
  90. $Tokens = $DB->to_array();
  91. $DB->query('SELECT FOUND_ROWS()');
  92. list($NumResults) = $DB->next_record();
  93. $Pages = Format::get_pages($Page, $NumResults, 25);
  94. ?>
  95. <div class="header">
  96. <h2>
  97. Freeleech token history for
  98. <?= Users::format_username($UserID, false, false, false) ?>
  99. </h2>
  100. </div>
  101. <div class="linkbox">
  102. <?= $Pages ?>
  103. </div>
  104. <table>
  105. <tr class="colhead_dark">
  106. <th>Torrent</th>
  107. <th>Time</th>
  108. <th>Expired</th>
  109. <?php if (check_perms('users_mod')) { ?>
  110. <th>Downloaded</th>
  111. <th>Tokens used</th>
  112. <?php } ?>
  113. </tr>
  114. <?php
  115. foreach ($Tokens as $Token) {
  116. $GroupIDs[] = $Token['GroupID'];
  117. }
  118. $Artists = Artists::get_artists($GroupIDs);
  119. foreach ($Tokens as $Token) {
  120. list($TorrentID, $GroupID, $Time, $Expired, $Downloaded, $Uses, $Name) = $Token;
  121. if ($Name !== '') {
  122. $Name = "<a href='torrents.php?torrentid=$TorrentID'>$Name</a>";
  123. } else {
  124. $Name = "(<i>Deleted torrent <a href='log.php?search=Torrent+$TorrentID'>$TorrentID</a></i>)";
  125. }
  126. $ArtistName = Artists::display_artists($Artists[$GroupID]);
  127. if ($ArtistName) {
  128. $Name = $ArtistName.$Name;
  129. } ?>
  130. <tr class="row">
  131. <td>
  132. <?= $Name ?>
  133. </td>
  134. <td>
  135. <?= time_diff($Time) ?>
  136. </td>
  137. <td>
  138. <?= ($Expired ? 'Yes' : 'No') ?>
  139. <?= (check_perms('users_mod') && !$Expired)
  140. ? " <a href='userhistory.php?action=token_history&amp;expire=1&amp;userid=$UserID&amp;torrentid=$TorrentID'>(expire)</a>"
  141. : ''; ?>
  142. </td>
  143. <?php if (check_perms('users_mod')) { ?>
  144. <td>
  145. <?= Format::get_size($Downloaded) ?>
  146. </td>
  147. <td>
  148. <?= $Uses ?>
  149. </td>
  150. <?php } ?>
  151. </tr>
  152. <?php
  153. } ?>
  154. </table>
  155. <div class="linkbox">
  156. <?= $Pages ?>
  157. </div>
  158. <?php View::show_footer();