Browse Source

Actually include files for price-changing coin badge

spaghetti 8 years ago
parent
commit
617229e85a
2 changed files with 89 additions and 0 deletions
  1. 89
    0
      sections/store/coinbadge.php
  2. BIN
      static/common/badges/oppaicoin.png

+ 89
- 0
sections/store/coinbadge.php View File

@@ -0,0 +1,89 @@
1
+<?
2
+$UserID = $LoggedUser['ID'];
3
+
4
+$DB->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->query("
12
+    INSERT INTO misc
13
+           (Name,        First, Second)
14
+    VALUES ('CoinBadge', 0,     1000)");
15
+  list($Purchases, $Price) = [0, 1000];
16
+}
17
+
18
+View::show_header('Store');
19
+?>
20
+
21
+<div class="thin">
22
+
23
+<? if (isset($_GET['confirm']) && $_GET['confirm'] == 1) {
24
+  $DB->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->query("
34
+        UPDATE users_main
35
+        SET BonusPoints = BonusPoints - $Price
36
+        WHERE ID = $UserID");
37
+      $DB->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->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
+
56
+  if (isset($Err)) { ?>
57
+    <h2 id="general">Purchase Failed</h2>
58
+    <div class="box pad">
59
+      <p>Error: <?=$Err?></p>
60
+      <p>Transaction aborted</p>
61
+      <p><a href='/store.php'>Back to Store</a></p>
62
+    </div>
63
+  <? } else { ?>
64
+    <h2 id="general">Purchase Successful</h2>
65
+    <div class="box pad">
66
+      <p>You bought the Oppaicoin badge</p>
67
+      <p>This badge has been purchased <?=number_format($Purchases)?> times and now costs <?=number_format($Price)?> <?=BONUS_POINTS?>.</p>
68
+    </div>
69
+<? } ?>
70
+<?
71
+} else { ?>
72
+  <h2 id="general">Purchase Oppaicoin Badge?</h2>
73
+  <div class="box pad">
74
+    <p><?=number_format($Purchases)?> people have bought this badge</p>
75
+    <p>Current cost: <?=number_format($Price)?> <?=BONUS_POINTS?></p>
76
+    <? if (Badges::has_badge($UserID, ['BadgeID' => 255])) { ?>
77
+    <p>You already own this badge</p>
78
+    <? } else { ?>
79
+    <form action="store.php">
80
+      <input type="hidden" name="item" value="coinbadge">
81
+      <input type="hidden" name="confirm" value="1">
82
+      <input type="submit" value="Purchase">
83
+    </form>
84
+    <? } ?>
85
+  </div>
86
+<? } ?>
87
+
88
+</div>
89
+<? View::show_footer(); ?>

BIN
static/common/badges/oppaicoin.png View File


Loading…
Cancel
Save