-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbazaar.php
209 lines (185 loc) · 7.66 KB
/
bazaar.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
<?php
/***************************************************************************
*
* 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.
*
* Portions of this program are derived from publicly licensed software
* projects including, but not limited to phpBB, Magelo Clone,
* EQEmulator, EQEditor, and Allakhazam Clone.
*
* Author:
* Maudigan(Airwalking)
*
* September 26, 2014 - Maudigan
* Updated character table name
* September 28, 2014 - Maudigan
* added code to monitor database performance
***************************************************************************/
define('INCHARBROWSER', true);
include_once("include/config.php");
include_once("include/debug.php");
include_once("include/sql.php");
include_once("include/global.php");
include_once("include/language.php");
include_once("include/functions.php");
include_once("include/itemclass.php");
global $game_db;
//load variables from the GET
$start = (($_GET['start']) ? $_GET['start'] : "0");
$orderby = (($_GET['orderby']) ? $_GET['orderby'] : "Name");
$class = (($_GET['class']!="") ? $_GET['class'] : "-1");
$race = (($_GET['race']!="") ? $_GET['race'] : "-1");
$slot = (($_GET['slot']!="") ? $_GET['slot'] : "-1");
$type = (($_GET['type']!="") ? $_GET['type'] : "-1");
$pricemin = $_GET['pricemin'];
$pricemax = $_GET['pricemax'];
$item = $_GET['item'];
$direction = (($_GET['direction']=="DESC") ? "DESC" : "ASC");
$perpage=25;
//build baselink
$baselink="bazaar.php?class=$class&race=$race&slot=$slot&type=$type&pricemin=$pricemin&pricemax=$pricemax&item=$item";
//security against sql injection
if (!IsAlphaSpace($item)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ITEM_ALPHA']);
if (!IsAlphaSpace($orderby)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ORDER_ALPHA']);
if (!is_numeric($start)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_START_NUMERIC']);
if (!is_numeric($pricemin) && $pricemin != "") message_die($language['MESSAGE_ERROR'],$language['MESSAGE_PRICE_NUMERIC']);
if (!is_numeric($pricemax) && $pricemax != "") message_die($language['MESSAGE_ERROR'],$language['MESSAGE_PRICE_NUMERIC']);
if (!is_numeric($class)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_CLASS_NUMERIC']);
if (!is_numeric($race)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_RACE_NUMERIC']);
if (!is_numeric($slot)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_SLOT_NUMERIC']);
if (!is_numeric($type)) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_TYPE_NUMERIC']);
//dont display bazaaar if blocked in config.php
if ($blockbazaar && !isAdmin()) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ITEM_NO_VIEW']);
// pull the items from the database
//updated character table name 9/26/2014
$where = "";
$divider = " WHERE ";
if ($item) {
$where .= $divider."items.Name LIKE '%".str_replace("_", "%", str_replace(" ","%",$item))."%'";
$divider = " AND ";
}
if ($pricemin) {
$modprice = $pricemin * 1000;
$where .= $divider."trader.item_cost >= $modprice";
$divider = " AND ";
}
if ($pricemax) {
$modprice = $pricemax * 1000;
$where .= $divider."trader.item_cost <= $modprice";
$divider = " AND ";
}
if($class > -1) {
$where .= $divider."items.classes & $class";
$divider = " AND ";
}
if($race > -1) {
$where .= $divider."items.races & $race";
$divider = " AND ";
}
if($type > -1) {
$where .= $divider."items.itemtype = $type";
$divider = " AND ";
}
if($slot > -1) {
$where .= $divider."items.slots & $slot";
$divider = " AND ";
}
$select = "SELECT character_data.name as charactername, items.*, trader.item_cost as tradercost
FROM character_data
INNER JOIN trader
ON character_data.id = trader.char_id
INNER JOIN items
ON items.id = trader.item_id ";
$query = $select.$where;
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$results = $game_db->query($query);
$totalitems = numRows($results);
if (!$totalitems) message_die($language['MESSAGE_ERROR'],$language['MESSAGE_NO_RESULTS_ITEMS']);
$query = $select.$where." ORDER BY $orderby $direction LIMIT $start, $perpage;";
if (defined('DB_PERFORMANCE')) dbp_query_stat('query', $query); //added 9/28/2014
$results = $game_db->query($query);
//drop page
$d_title = " - ".$language['PAGE_TITLES_BAZAAR'];
include("include/header.php");
//build body template
$template->set_filenames(array(
'bazaar' => 'bazaar_body.tpl')
);
$template->assign_vars(array(
'ITEM' => $item,
'ORDER_LINK' => $baselink."&start=$start&direction=".(($direction=="ASC") ? "DESC":"ASC"),
'PAGINATION' => generate_pagination("$baselink&orderby=$orderby&direction=$direction", $totalitems, $perpage, $start, true),
'PRICE_MIN' => $pricemin,
'PRICE_MAX' => $pricemax,
'L_BAZAAR' => $language['BAZAAR_BAZAAR'],
'L_NAME' => $language['BAZAAR_NAME'],
'L_PRICE' => $language['BAZAAR_PRICE'],
'L_ITEM' => $language['BAZAAR_ITEM'],
'L_SEARCH' => $language['BAZAAR_SEARCH'],
'L_SEARCH_NAME' => $language['BAZAAR_SEARCH_NAME'],
'L_SEARCH_CLASS' => $language['BAZAAR_SEARCH_CLASS'],
'L_SEARCH_RACE' => $language['BAZAAR_SEARCH_RACE'],
'L_SEARCH_SLOT' => $language['BAZAAR_SEARCH_SLOT'],
'L_SEARCH_TYPE' => $language['BAZAAR_SEARCH_TYPE'],
'L_SEARCH_PRICE_MIN' => $language['BAZAAR_SEARCH_PRICE_MIN'],
'L_SEARCH_PRICE_MAX' => $language['BAZAAR_SEARCH_PRICE_MAX'])
);
//dump items
$slotcounter = 0;
foreach($results AS $row) {
$tempitem = new item($row);
$price = $row["tradercost"];
$plat = floor($price/1000);
$price = $price % 1000;
$gold = floor($price/100);
$price = $price % 100;
$silver = floor($price/10);
$copper = $price % 10;
$template->assign_block_vars("items", array(
'SELLER' => $row['charactername'],
'PRICE' => (($plat)?$plat."p ":"").(($silver)?$silver."s ":"").(($gold)?$gold."g ":"").(($copper)?$copper."c ":""),
'NAME' => $tempitem->name(),
'ID' => $tempitem->id(),
'HTML' => $tempitem->html(),
'SLOT' => $slotcounter)
);
$slotcounter ++;
}
//built combo box options
foreach ($language['BAZAAR_ARRAY_SEARCH_TYPE'] as $key => $value ) {
$template->assign_block_vars("select_type", array(
'VALUE' => $key,
'OPTION' => $value,
'SELECTED' => (($type == $key) ? "selected":""))
);
}
foreach ($language['BAZAAR_ARRAY_SEARCH_CLASS'] as $key => $value ) {
$template->assign_block_vars("select_class", array(
'VALUE' => $key,
'OPTION' => $value,
'SELECTED' => (($class == $key) ? "selected":""))
);
}
foreach ($language['BAZAAR_ARRAY_SEARCH_RACE'] as $key => $value ) {
$template->assign_block_vars("select_race", array(
'VALUE' => $key,
'OPTION' => $value,
'SELECTED' => (($race == $key) ? "selected":""))
);
}
foreach ($language['BAZAAR_ARRAY_SEARCH_SLOT'] as $key => $value ) {
$template->assign_block_vars("select_slot", array(
'VALUE' => $key,
'OPTION' => $value,
'SELECTED' => (($slot == $key) ? "selected":""))
);
}
$template->pparse('bazaar');
$template->destroy;
//added to monitor database performance 9/28/2014
if (defined('DB_PERFORMANCE')) print dbp_dump_buffer('query');
include("include/footer.php");
?>