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.

badge.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. #declare(strict_types=1);
  3. $UserID = $LoggedUser['ID'];
  4. $BadgeID = $_GET['badge'];
  5. $ShopBadgeIDs = [40, 41, 42, 43, 44, 45, 46, 47, 48];
  6. $Prices = [
  7. 40 => 50,
  8. 41 => 100,
  9. 42 => 250,
  10. 43 => 500,
  11. 44 => 1000,
  12. 45 => 2500,
  13. 46 => 5000,
  14. 47 => 10000,
  15. 48 => 25000
  16. ];
  17. if (!$BadgeID) {
  18. $Err = 'No badge specified';
  19. } elseif (!in_array($BadgeID, $ShopBadgeIDs)) {
  20. $Err = 'Invalid badge ID';
  21. } elseif (Badges::has_badge($UserID, $BadgeID)) {
  22. $Err = 'You already have this badge';
  23. } elseif ((int) $BadgeID !== $ShopBadgeIDs[0] && !Badges::has_badge($UserID, $ShopBadgeIDs[array_search($BadgeID, $ShopBadgeIDs)-1])) {
  24. $Err = "You haven't purchased the badges before this one!";
  25. }
  26. if (isset($_GET['confirm']) && $_GET['confirm'] === '1') {
  27. if (!isset($Err)) {
  28. $DB->query("
  29. SELECT BonusPoints
  30. FROM users_main
  31. WHERE ID = $UserID");
  32. if ($DB->has_results()) {
  33. list($BP) = $DB->next_record();
  34. $BP = (int) $BP;
  35. if ($BP >= $Prices[$BadgeID]) {
  36. if (!Badges::award_badge($UserID, $BadgeID)) {
  37. $Err = 'Could not award badge, unknown error occurred.';
  38. } else {
  39. $DB->query("
  40. UPDATE users_main
  41. SET BonusPoints = BonusPoints - " . $Prices[$BadgeID] ."
  42. WHERE ID = $UserID");
  43. $DB->query("
  44. UPDATE users_info
  45. SET AdminComment = CONCAT('".sqltime()." - Purchased badge $BadgeID from store\n\n', AdminComment)
  46. WHERE UserID = $UserID");
  47. $Cache->delete_value("user_info_heavy_$UserID");
  48. }
  49. } else {
  50. $Err = 'Not enough '.BONUS_POINTS.'.';
  51. }
  52. }
  53. }
  54. View::show_header('Store'); ?>
  55. <div>
  56. <h2 id='general'>
  57. Purchase <?=isset($Err)?'Failed':'Successful'?>
  58. </h2>
  59. <div class='box pad'>
  60. <p>
  61. <?=isset($Err)?'Error: '.$Err:'You have purchased a badge'?>
  62. </p>
  63. <p>
  64. <a href='/store.php'>Back to Store</a>
  65. </p>
  66. </div>
  67. </div>
  68. <?php
  69. } else {
  70. View::show_header('Store'); ?>
  71. <div>
  72. <h2 id='general'>Purchase Badge?</h2>
  73. <div class='box pad'>
  74. <p>
  75. Badge cost:
  76. <?=number_format($Prices[$BadgeID])?>
  77. <?=BONUS_POINTS?>
  78. </p>
  79. <?php if (isset($Err)) { ?>
  80. <p>Error: <?=$Err?>
  81. </p>
  82. <?php } else { ?>
  83. <form action="store.php">
  84. <input type="hidden" name="item" value="badge">
  85. <input type="hidden" name="badge" value="<?=$BadgeID?>">
  86. <input type="hidden" name="confirm" value="1">
  87. <input type="submit" value="Purchase">
  88. <?php } ?>
  89. <p>
  90. <a href='/store.php'>Back to Store</a>
  91. </p>
  92. </div>
  93. </div>
  94. <?php
  95. }
  96. View::show_footer();