-
Notifications
You must be signed in to change notification settings - Fork 3
/
itemmarket.php
executable file
·275 lines (259 loc) · 9.33 KB
/
itemmarket.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/*
MCCodes FREE
itemmarket.php Rev 1.1.0
Copyright (C) 2005-2012 Dabomstew
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
session_start();
require "global_func.php";
if ($_SESSION['loggedin'] == 0)
{
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is =
mysql_query(
"SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
$c) or die(mysql_error());
$ir = mysql_fetch_array($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
print "<h3>Item Market</h3>";
switch ($_GET['action'])
{
case "buy":
item_buy();
break;
case "gift1":
item_gift1();
break;
case "gift2":
item_gift2();
break;
case "remove":
item_remove();
break;
default:
imarket_index();
break;
}
function imarket_index()
{
global $ir, $c, $userid, $h;
print
"Viewing all listings...
<table width=75%> <tr style='background:gray'> <th>Adder</th> <th>Item</th> <th>Price</th> <th>Links</th> </tr>";
$q =
mysql_query(
"SELECT im.*, i.*, u.*,it.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid LEFT JOIN users u ON u.userid=im.imADDER LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid ORDER BY i.itmtype, i.itmname ASC",
$c);
$lt = "";
while ($r = mysql_fetch_array($q))
{
if ($lt != $r['itmtypename'])
{
$lt = $r['itmtypename'];
print
"\n<tr style='background: gray;'><th colspan=4>{$lt}</th></tr>";
}
if ($r['imADDER'] == $userid)
{
$link =
"[<a href='itemmarket.php?action=remove&ID={$r['imID']}'>Remove</a>]";
}
else
{
$link =
"[<a href='itemmarket.php?action=buy&ID={$r['imID']}'>Buy</a>] [<a href='itemmarket.php?action=gift1&ID={$r['imID']}'>Gift</a>]";
}
print
"\n<tr> <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td> <td>{$r['itmname']}</td> <td>\$"
. number_format($r['imPRICE'])
. "</td> <td>[<a href='iteminfo.php?ID={$r['itmid']}'>Info</a>] $link</td> </tr>";
}
print "</table>";
}
function item_remove()
{
global $ir, $c, $userid, $h;
$q =
mysql_query(
"SELECT im.*,i.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid WHERE imID={$_GET['ID']} AND imADDER=$userid",
$c);
if (!mysql_num_rows($q))
{
print
"Error, either this item does not exist, or you are not the owner.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r = mysql_fetch_array($q);
mysql_query("INSERT INTO inventory VALUES(NULL,{$r['imITEM']},$userid,1)",
$c) or die(mysql_error());
$i = mysql_insert_id($c);
mysql_query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}", $c);
mysql_query(
"INSERT INTO imremovelogs VALUES(NULL, {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imID']}, $i, "
. time()
. ", '{$ir['username']} removed a {$r['itmname']} from the item market.')",
$c);
print
"Item removed from market!<br />
<a href='itemmarket.php'>> Back</a>";
}
function item_buy()
{
global $ir, $c, $userid, $h;
$q =
mysql_query(
"SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}",
$c);
if (!mysql_num_rows($q))
{
print
"Error, either this item does not exist, or it has already been bought.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r = mysql_fetch_array($q);
if ($r['imPRICE'] > $ir['money'])
{
print
"Error, you do not have the funds to buy this item.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
mysql_query("INSERT INTO inventory VALUES(NULL,{$r['imITEM']},$userid,1)",
$c) or die(mysql_error());
$i = mysql_insert_id($c);
mysql_query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}", $c);
mysql_query(
"UPDATE users SET money=money-{$r['imPRICE']} where userid=$userid",
$c);
mysql_query(
"UPDATE users SET money=money+{$r['imPRICE']} where userid={$r['imADDER']}",
$c);
event_add($r['imADDER'],
"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} item from the market for \$"
. number_format($r['imPRICE']) . ".", $c);
mysql_query(
"INSERT INTO imbuylogs VALUES(NULL, {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, "
. time()
. ", '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']}')",
$c);
print
"You bought the {$r['itmname']} from the market for \$"
. number_format($r['imPRICE']) . ".";
}
function item_gift1()
{
global $ir, $c, $userid, $h;
$q =
mysql_query(
"SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_GET['ID']}",
$c);
if (!mysql_num_rows($q))
{
print
"Error, either this item does not exist, or it has already been bought.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r = mysql_fetch_array($q);
if ($r['imPRICE'] > $ir['money'])
{
print
"Error, you do not have the funds to buy this item.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
print
"Buying the <b>{$r['itmname']}</b> for \$"
. number_format($r['imPRICE'])
. " as a gift...<br />
<form action='itemmarket.php?action=gift2' method='post'>
<input type='hidden' name='ID' value='{$_GET['ID']}' />
User to give gift to: " . user_dropdown($c, 'user')
. "<br />
<input type='submit' value='Buy Item and Send Gift' /></form>";
}
function item_gift2()
{
global $ir, $c, $userid, $h;
$q =
mysql_query(
"SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID={$_POST['ID']}",
$c);
if (!mysql_num_rows($q))
{
print
"Error, either this item does not exist, or it has already been bought.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r = mysql_fetch_array($q);
if ($r['imPRICE'] > $ir['money'])
{
print
"Error, you do not have the funds to buy this item.<br />
<a href='itemmarket.php'>> Back</a>";
$h->endpage();
exit;
}
mysql_query(
"INSERT INTO inventory VALUES(NULL,{$r['imITEM']},{$_POST['user']},1)",
$c) or die(mysql_error());
$i = mysql_insert_id($c);
mysql_query("DELETE FROM itemmarket WHERE imID={$_POST['ID']}", $c);
mysql_query(
"UPDATE users SET money=money-{$r['imPRICE']} where userid=$userid",
$c);
mysql_query(
"UPDATE users SET money=money+{$r['imPRICE']} where userid={$r['imADDER']}",
$c);
event_add($r['imADDER'],
"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} item from the market for \$"
. number_format($r['imPRICE']) . ".", $c);
event_add($_POST['user'],
"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> bought you a {$r['itmname']} from the item market as a gift.",
$c);
$u = mysql_query("SELECT * FROM users WHERE userid={$_POST['user']}", $c);
$uname = mysql_result($u, 0, 1);
mysql_query(
"INSERT INTO imbuylogs VALUES(NULL, {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, "
. time()
. ", '{$ir['username']} bought a {$r['itmname']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')",
$c);
print
"You bought the {$r['itmname']} from the market for \$"
. number_format($r['imPRICE'])
. " and sent the gift to $uname.";
}
$h->endpage();