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

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