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.7KB

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