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

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