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

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