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.

coinbadge.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. $UserID = $LoggedUser['ID'];
  3. $DB->query("
  4. SELECT First, Second
  5. FROM misc
  6. WHERE Name='CoinBadge'");
  7. if ($DB->has_results()) {
  8. list($Purchases, $Price) = $DB->next_record();
  9. } else {
  10. $DB->query("
  11. INSERT INTO misc
  12. (Name, First, Second)
  13. VALUES ('CoinBadge', 0, 1000)");
  14. list($Purchases, $Price) = [0, 1000];
  15. }
  16. View::show_header('Store');
  17. ?>
  18. <div>
  19. <?php
  20. if (isset($_GET['confirm'])
  21. && $_GET['confirm'] === 1
  22. && !Badges::has_badge($UserID, 255)) {
  23. $DB->query("
  24. SELECT BonusPoints
  25. FROM users_main
  26. WHERE ID = $UserID");
  27. list($Points) = $DB->has_results() ? $DB->next_record() : [0];
  28. if ($Points > $Price) {
  29. if (!Badges::award_badge($UserID, 255)) {
  30. $Err = 'Could not award badge, unknown error occurred.';
  31. } else {
  32. $DB->query("
  33. UPDATE users_main
  34. SET BonusPoints = BonusPoints - $Price
  35. WHERE ID = $UserID");
  36. $DB->query("
  37. UPDATE users_info
  38. SET AdminComment = CONCAT('".sqltime()." - Purchased badge 255 from store\n\n', AdminComment)
  39. WHERE UserID = $UserID");
  40. $Cache->delete_value("user_info_heavy_$UserID");
  41. // Calculate new badge values
  42. $Purchases += 1;
  43. $x = $Purchases;
  44. $Price = 1000+$x*(10000+1400*((sin($x/1.3)+cos($x/4.21))+(sin($x/2.6)+cos(2*$x/4.21))/2));
  45. $DB->query("
  46. UPDATE misc
  47. SET First = $Purchases,
  48. Second = $Price
  49. WHERE Name = 'CoinBadge'");
  50. }
  51. } else {
  52. $Err = 'Not enough '.BONUS_POINTS.'.';
  53. }
  54. if (isset($Err)) { ?>
  55. <h2>Purchase Failed</h2>
  56. <div class="box pad">
  57. <p>
  58. Error:
  59. <?=$Err?>
  60. </p>
  61. <p>
  62. Transaction aborted
  63. </p>
  64. <p>
  65. <a href='/store.php'>Back to Store</a>
  66. </p>
  67. </div>
  68. <?php
  69. } else { ?>
  70. <h2>Purchase Successful</h2>
  71. <div class="box pad">
  72. <p>You bought the Oppaicoin badge</p>
  73. <p>This badge has been purchased <?=number_format($Purchases)?>
  74. times and now costs <?=number_format($Price)?> <?=BONUS_POINTS?>.</p>
  75. </div>
  76. <?php } ?>
  77. <?php
  78. } else {
  79. if (Badges::has_badge($UserID, 255)) {
  80. ?>
  81. <h2>Oppaicoin Status</h2>
  82. <?php
  83. } else {
  84. ?>
  85. <h2>Purchase Oppaicoin Badge?</h2>
  86. <?php
  87. } ?>
  88. <div class="box pad">
  89. <p><?=number_format($Purchases)?> people have bought this badge
  90. </p>
  91. <p>Current cost: <?=number_format($Price)?> <?=BONUS_POINTS?>
  92. </p>
  93. <?php if (Badges::has_badge($UserID, 255)) { ?>
  94. <p>You already own this badge</p>
  95. <?php } else { ?>
  96. <form action="store.php">
  97. <input type="hidden" name="item" value="coinbadge">
  98. <input type="hidden" name="confirm" value="1">
  99. <input type="submit" value="Purchase">
  100. </form>
  101. <?php } ?>
  102. </div>
  103. <?php
  104. } ?>
  105. </div>
  106. <?php
  107. View::show_footer();