Oppaitime'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

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