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.

donation_log.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. #declare(strict_types = 1);
  3. if (!check_perms('admin_donor_log')) {
  4. error(403);
  5. }
  6. include(SERVER_ROOT.'/sections/donate/config.php');
  7. define('DONATIONS_PER_PAGE', 50);
  8. list($Page, $Limit) = Format::page_limit(DONATIONS_PER_PAGE);
  9. $AfterDate = $_GET['after_date'];
  10. $BeforeDate = $_GET['before_date'];
  11. $DateSearch = false;
  12. if (!empty($AfterDate) && !empty($BeforeDate)) {
  13. list($Y, $M, $D) = explode('-', $AfterDate);
  14. if (!checkdate($M, $D, $Y)) {
  15. error('Incorrect "after" date format');
  16. }
  17. list($Y, $M, $D) = explode('-', $BeforeDate);
  18. if (!checkdate($M, $D, $Y)) {
  19. error('Incorrect "before" date format');
  20. }
  21. $AfterDate = db_string($AfterDate);
  22. $BeforeDate = db_string($BeforeDate);
  23. $DateSearch = true;
  24. }
  25. $Operator = "WHERE";
  26. $SQL = "
  27. SELECT
  28. SQL_CALC_FOUND_ROWS
  29. d.UserID,
  30. d.Amount,
  31. d.Currency,
  32. d.Email,
  33. d.Time,
  34. d.Source,
  35. m.Username,
  36. d.AddedBy,
  37. d.Reason
  38. FROM donations AS d
  39. LEFT JOIN users_main AS m ON m.ID = d.UserID ";
  40. if (!empty($_GET['email'])) {
  41. $SQL .= "
  42. $Operator d.Email LIKE '%".db_string($_GET['email'])."%' ";
  43. $Operator = "AND";
  44. }
  45. if (!empty($_GET['username'])) {
  46. $SQL .= "
  47. $Operator m.Username LIKE '%".db_string($_GET['username'])."%' ";
  48. $Operator = "AND";
  49. }
  50. if ($DateSearch) {
  51. $SQL .= "$Operator d.Time BETWEEN '$AfterDate' AND '$BeforeDate' ";
  52. $Operator = "AND";
  53. }
  54. $SQL .= "
  55. ORDER BY d.Time DESC
  56. LIMIT $Limit";
  57. $DB->query($SQL);
  58. $Donations = $DB->to_array();
  59. $DB->query('SELECT FOUND_ROWS()');
  60. list($Results) = $DB->next_record();
  61. $DB->query("SELECT SUM(Amount) FROM donations");
  62. list($Total) = $DB->next_record();
  63. /*
  64. if (empty($_GET['email']) && empty($_GET['username']) && empty($_GET['source']) && !isset($_GET['page']) && !$DonationTimeline = $Cache->get_value('donation_timeline')) {
  65. include(SERVER_ROOT.'/classes/charts.class.php');
  66. $DB->query("
  67. SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, SUM(Amount)
  68. FROM donations
  69. GROUP BY Month
  70. ORDER BY Time DESC
  71. LIMIT 1, 18");
  72. $Timeline = array_reverse($DB->to_array());
  73. $Area = new AREA_GRAPH(880, 160, array('Break' => 1));
  74. foreach ($Timeline as $Entry) {
  75. list($Label, $Amount) = $Entry;
  76. $Area->add($Label, $Amount);
  77. }
  78. $Area->transparent();
  79. $Area->grid_lines();
  80. $Area->color('3d7930');
  81. $Area->lines(2);
  82. $Area->generate();
  83. $DonationTimeline = $Area->url();
  84. $Cache->cache_value('donation_timeline', $DonationTimeline, mktime(0, 0, 0, date('n') + 1, 2));
  85. }
  86. */
  87. View::show_header('Donation log');
  88. /*
  89. if (empty($_GET['email']) && empty($_GET['source']) && empty($_GET['username']) && !isset($_GET['page'])) { ?>
  90. <div class="box pad">
  91. <img src="<?=$DonationTimeline?>"
  92. alt="Donation timeline. The &quot;y&quot; axis is donation amount." />
  93. </div>
  94. <br />
  95. <?php
  96. } */ ?>
  97. <div>
  98. <form class="search_form" name="donation_log" action="" method="get">
  99. <input type="hidden" name="action" value="donation_log" />
  100. <table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
  101. <tr>
  102. <td class="label"><strong>Username:</strong></td>
  103. <td>
  104. <input type="search" name="username" size="60" value="<?php if (!empty($_GET['username'])) {
  105. echo display_str($_GET['username']);
  106. } ?>" />
  107. </td>
  108. </tr>
  109. <tr>
  110. <td class="label"><strong>Email:</strong></td>
  111. <td>
  112. <input type="search" name="email" size="60" value="<?php if (!empty($_GET['email'])) {
  113. echo display_str($_GET['email']);
  114. } ?>" />
  115. </td>
  116. </tr>
  117. <tr>
  118. <td class="label"><strong>Source:</strong></td>
  119. <td>
  120. <input type="search" name="source" size="60" value="<?php if (!empty($_GET['source'])) {
  121. echo display_str($_GET['source']);
  122. } ?>" />
  123. </td>
  124. </tr>
  125. <tr>
  126. <td class="label"><strong>Date Range:</strong></td>
  127. <td>
  128. <input type="date" name="after_date" />
  129. <input type="date" name="before_date" />
  130. </td>
  131. </tr>
  132. <tr>
  133. <td>
  134. <input type="submit" value="Search donation log" />
  135. </td>
  136. </tr>
  137. </table>
  138. </form>
  139. </div>
  140. <br />
  141. <div class="linkbox">
  142. <?php
  143. $Pages = Format::get_pages($Page, $Results, DONATIONS_PER_PAGE, 11);
  144. echo $Pages;
  145. ?>
  146. </div>
  147. <table width="100%">
  148. <tr class="colhead">
  149. <td>User</td>
  150. <td>Amount</td>
  151. <td>Email</td>
  152. <td>Source</td>
  153. <td>Reason</td>
  154. <td>Time</td>
  155. </tr>
  156. <?php
  157. $PageTotal = 0;
  158. foreach ($Donations as $Donation) {
  159. $PageTotal += $Donation['Amount']; ?>
  160. <tr>
  161. <td>
  162. <?=Users::format_username($Donation['UserID'], true)?>
  163. (<?=Users::format_username($Donation['AddedBy'])?>)
  164. </td>
  165. <td>
  166. <?=display_str($Donation['Amount'])?>
  167. </td>
  168. <td>
  169. <?=display_str($Donation['Email'])?>
  170. </td>
  171. <td>
  172. <?=display_str($Donation['Source'])?>
  173. </td>
  174. <td>
  175. <?=display_str($Donation['Reason'])?>
  176. </td>
  177. <td>
  178. <?=time_diff($Donation['Time'])?>
  179. </td>
  180. </tr>
  181. <?php
  182. } ?>
  183. <tr class="colhead">
  184. <td>Page Total</td>
  185. <td>
  186. <?=$PageTotal?>
  187. </td>
  188. <td>Total</td>
  189. <td colspan="3">
  190. <?=$Total?>
  191. </td>
  192. </tr>
  193. </table>
  194. <div class="linkbox">
  195. <?=$Pages?>
  196. </div>
  197. <?php View::show_footer();