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.

badge.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?
  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'?></h2>
  46. <div class='box pad' style='padding: 10px 10px 10px 20px;'>
  47. <p><?=isset($Err)?'Error: '.$Err:'You have purchased a badge'?></p>
  48. <p><a href='/store.php'>Back to Store</a></p>
  49. </div>
  50. </div>
  51. <? } else {
  52. View::show_header('Store'); ?>
  53. <div class='thin'>
  54. <h2 id='general'>Purchase Badge?</h2>
  55. <div class='box pad' style='padding: 10px 10px 10px 20px;'>
  56. <p>Badge cost: <?=number_format($Prices[$BadgeID])?> <?=BONUS_POINTS?></p>
  57. <? if (isset($Err)) { ?>
  58. <p>Error: <?=$Err?></p>
  59. <? } else { ?>
  60. <form action="store.php">
  61. <input type="hidden" name="item" value="badge">
  62. <input type="hidden" name="badge" value="<?=$BadgeID?>">
  63. <input type="hidden" name="confirm" value="1">
  64. <input type="submit" value="Purchase">
  65. <? } ?>
  66. <p><a href='/store.php'>Back to Store</a></p>
  67. </div>
  68. </div>
  69. <? }
  70. View::show_footer(); ?>