forked from Znote/ZnoteAAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarket.php
180 lines (177 loc) · 6.24 KB
/
market.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
$server = $config['shop']['imageServer'];
$imageType = $config['shop']['imageType'];
$items = getItemList();
$compare = &$_GET['compare'];
// If you are not comparing any items, present the list.
if (!$compare) {
$cache = new Cache('engine/cache/market');
$cache->setExpiration(6);
if ($cache->hasExpired()) {
$offers = array(
'wts' => mysql_select_multi("SELECT `id`, `itemtype` AS `item_id`, `amount`, `price`, `created`, `anonymous`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `player_name` FROM `market_offers` WHERE `sale` = 1 ORDER BY `created` DESC;"),
'wtb' => mysql_select_multi("SELECT `id`, `itemtype` AS `item_id`, `amount`, `price`, `created`, `anonymous`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `player_name` FROM `market_offers` WHERE `sale` = 0 ORDER BY `created` DESC;")
);
$cache->setContent($offers);
$cache->save();
} else {
$offers = $cache->load();
}
?>
<h1>Marketplace</h1>
<p>You can buy and sell items by clicking on the <a target="_BLANK" href="http://4.ii.gl/CAPcBp.png">market in depot.</a> <br>To sell an item: Place item inside your depot, click on market, search for your item and sell it.</p>
<h2>WTS: Want to sell</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
<td>Added</td>
<td>By</td>
<td>Compare</td>
</tr>
<?php
foreach (($offers['wts'] ? $offers['wts'] : array()) as $o) {
?>
<tr>
<td><?php echo (isset($items[$o['item_id']])) ? $items[$o['item_id']] : $o['item_id']; ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
<td><?php echo getClock($o['created'], true, true); ?></td>
<td><?php echo ($o['anonymous'] == 1) ? 'Anonymous' : "<a target='_BLANK' href='characterprofile.php?name=".$o['player_name']."'>".$o['player_name']."</a>"; ?></td>
<td><a href="?compare=<?php echo $o['item_id']; ?>"><button>Compare</button></a></td>
</tr>
<?php
}
?>
</table>
<h2>WTB: Want to buy</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
<td>Added</td>
<td>By</td>
<td>Compare</td>
</tr>
<?php
foreach (($offers['wtb'] ? $offers['wtb'] : array()) as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
<td><?php echo getClock($o['created'], true, true); ?></td>
<td><?php echo ($o['anonymous'] == 1) ? 'Anonymous' : "<a target='_BLANK' href='characterprofile.php?name=".$o['player_name']."'>".$o['player_name']."</a>"; ?></td>
<td><a href="?compare=<?php echo $o['item_id']; ?>"><button>Compare</button></a></td>
</tr>
<?php
}
?>
</table>
<?php
} else {
// Else You want to compare price
$compare = (int)$compare;
// First list active bids
$offers = mysql_select_multi("SELECT `id`, `sale`, `itemtype` AS `item_id`, `amount`, `price`, `created`, `anonymous`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `player_name` FROM `market_offers` WHERE `itemtype`='$compare' ORDER BY `price` ASC;");
$historyOffers = mysql_select_multi("SELECT `id`, `itemtype` AS `item_id`, `amount`, `price`, `inserted`, `expires_at` FROM `market_history` WHERE `itemtype`='$compare' AND `state`=255 ORDER BY `price` ASC;");
$buylist = false;
// Markup
?>
<h1>Comparing item</h1>
<a href="market.php"><button>Go back</button></a>
<h2>Active offers</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
<td>Added</td>
<td>By</td>
</tr>
<?php
foreach (($offers ? $offers : array()) as $o) {
$wtb = false;
if ($o['sale'] == 0) {
$wtb = true;
if ($buylist === false) $buylist = array();
$buylist[] = $o;
} else {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
<td><?php echo getClock($o['created'], true, true); ?></td>
<td><?php echo ($o['anonymous'] == 1) ? 'Anonymous' : "<a target='_BLANK' href='characterprofile.php?name=".$o['player_name']."'>".$o['player_name']."</a>"; ?></td>
</tr>
<?php
}
}
?>
</table>
<?php
if ($buylist !== false) {
?>
<h2>Want to buy:</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
<td>Added</td>
<td>By</td>
</tr>
<?php
foreach ($buylist as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
<td><?php echo getClock($o['created'], true, true); ?></td>
<td><?php echo ($o['anonymous'] == 1) ? 'Anonymous' : "<a target='_BLANK' href='characterprofile.php?name=".$o['player_name']."'>".$o['player_name']."</a>"; ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
<h2>Old purchased offers</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
<td>Offer sold</td>
</tr>
<?php
foreach (($historyOffers ? $historyOffers : array()) as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
<td><?php echo getClock($o['inserted'], true, true); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
include 'layout/overall/footer.php'; ?>