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

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