Skip to content

Commit

Permalink
bazaar enhancement
Browse files Browse the repository at this point in the history
fixed an error in the join function that caused some rows to not display
added the ability to see/sort by a stat (like in game) when searching
the bazaar
  • Loading branch information
maudigan committed Jul 28, 2020
1 parent a48958e commit 6588dcf
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 31 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
v3.4.0
----------------------------------------------------------------------
bazaar enhancement

July 28, 2020 - fixed an error that hid some rows on the bazaar
results
added the ability to see/sort by stats in bazaar
results
(maudigan)

v3.3.3
----------------------------------------------------------------------
performance patch
Expand Down
35 changes: 30 additions & 5 deletions bazaar.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* May 17, 2020 - Maudigan
* rewrote the query logic to be a little cleaner, faster and to use
* the new php sort/join functions
* July 28, 2020
* put gold before silver in the item cost display
*
***************************************************************************/

Expand All @@ -61,6 +63,7 @@
$class = (($_GET['class']!="") ? $_GET['class'] : "-1");
$race = (($_GET['race']!="") ? $_GET['race'] : "-1");
$slot = (($_GET['slot']!="") ? $_GET['slot'] : "-1");
$stat = (($_GET['stat']!="") ? $_GET['stat'] : "-1");
$type = (($_GET['type']!="") ? $_GET['type'] : "-1");
$pricemin = $_GET['pricemin'];
$pricemax = $_GET['pricemax'];
Expand All @@ -71,7 +74,7 @@
$perpage=25;

//build baselink
$baselink=(($charbrowser_wrapped) ? $_SERVER['SCRIPT_NAME'] : "index.php") . "?page=bazaar&char=$seller&class=$class&race=$race&slot=$slot&type=$type&pricemin=$pricemin&pricemax=$pricemax&item=$item";
$baselink=(($charbrowser_wrapped) ? $_SERVER['SCRIPT_NAME'] : "index.php") . "?page=bazaar&char=$seller&class=$class&race=$race&slot=$slot&type=$type&pricemin=$pricemin&pricemax=$pricemax&item=$item&stat=$stat";

//security against sql injection
if (!IsAlphaSpace($item)) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ITEM_ALPHA']);
Expand All @@ -84,6 +87,7 @@
if (!is_numeric($race)) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_RACE_NUMERIC']);
if (!is_numeric($slot)) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_SLOT_NUMERIC']);
if (!is_numeric($type)) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_TYPE_NUMERIC']);
if (!array_key_exists ($stat, $language['BAZAAR_ARRAY_SEARCH_STAT'])) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_STAT_INVALID']);

//dont display bazaaar if blocked in config.php
if ($blockbazaar) cb_message_die($language['MESSAGE_ERROR'],$language['MESSAGE_ITEM_NO_VIEW']);
Expand Down Expand Up @@ -165,11 +169,11 @@


//DO A MANUAL SORT OF THE RESULTS
if ($orderby == 'tradercost') {
$sort_type = 'int';
if ($orderby == 'Name' || $orderby == 'charactername') {
$sort_type = 'string';
}
else {
$sort_type = 'string';
$sort_type = 'int';
}
sort_by($joined_results, $orderby, $direction, $sort_type);

Expand Down Expand Up @@ -225,6 +229,7 @@
'L_SEARCH_CLASS' => $language['BAZAAR_SEARCH_CLASS'],
'L_SEARCH_RACE' => $language['BAZAAR_SEARCH_RACE'],
'L_SEARCH_SLOT' => $language['BAZAAR_SEARCH_SLOT'],
'L_SEARCH_STAT' => $language['BAZAAR_SEARCH_STAT'],
'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'])
Expand All @@ -245,17 +250,30 @@
$copper = number_format($price % 10);
$cb_template->assign_both_block_vars("items", array(
'SELLER' => $lot['charactername'],
'PRICE' => (($plat)?$plat."p ":"").(($silver)?$silver."s ":"").(($gold)?$gold."g ":"").(($copper)?$copper."c ":""),
'PRICE' => (($plat)?$plat."p ":"").(($gold)?$gold."g ":"").(($silver)?$silver."s ":"").(($copper)?$copper."c ":""),
'NAME' => $tempitem->name(),
'ID' => $tempitem->id(),
'ICON' => $tempitem->icon(),
'LINK' => QuickTemplate($link_item, array('ITEM_ID' => $tempitem->id())),
'HTML' => $tempitem->html(),
'SLOT' => $slotcounter)
);
if ($stat != -1) {
$cb_template->assign_block_vars("items.stat_col", array(
'STAT' => $tempitem->fetchColumn($stat))
);
}
$slotcounter ++;
}

//if they selected a stat, output a conditional template display
if ($stat != -1) {
$cb_template->assign_block_vars("switch_stat", array(
'STAT' => $stat,
'L_STAT' => $language['BAZAAR_ARRAY_SEARCH_STAT'][$stat])
);
}


//built combo box options
foreach ($language['BAZAAR_ARRAY_SEARCH_TYPE'] as $key => $value ) {
Expand Down Expand Up @@ -286,6 +304,13 @@
'SELECTED' => (($slot == $key) ? "selected":""))
);
}
foreach ($language['BAZAAR_ARRAY_SEARCH_STAT'] as $key => $value ) {
$cb_template->assign_block_vars("select_stat", array(
'VALUE' => $key,
'OPTION' => $value,
'SELECTED' => (($stat == $key) ? "selected":""))
);
}


/*********************************************
Expand Down
49 changes: 28 additions & 21 deletions include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
* add function to get comma concatenated list of id's in an array
* add a function to join to arrays on a specific field
* add a function to sort arrays by sub element
* July 28, 2020 - Maudigan
* The manual_join function wasn't handling rows with the duplicate keys
* well since it was indexing the array by that key.
*
***************************************************************************/

Expand Down Expand Up @@ -146,56 +149,60 @@ function get_id_list($array, $key) {
}

//do a manual join of two db result sets
function manual_join($array1, $key1, $array2, $key2, $type = 'inner') {
function manual_join($left, $leftKey, $right, $rightKey, $type = 'inner') {

//return empty set if we dont have valid inputs
if (!is_array($array1) || !is_array($array2)) return array();

//index the left array by the left key
$left = array();
foreach ($array1 as $row) {
$left[$row[$key1]] = $row;
}

//index the right array by the right key
$right = array();
foreach ($array2 as $row) {
$right[$row[$key2]] = $row;
}
if (!is_array($left) || !is_array($right)) return array();

//right join
//if its a right join just swap the left/right
if ($type == 'right') {
$temp = $left;
$left = $right;
$right = $temp;
$temp = $leftKey;
$leftKey = $rightKey;
$rightKey = $temp;
$type = 'left';
}

//left join
$joined = array();
if ($type == 'left') {
foreach ($left as $key => $row) {
if (array_key_exists($key, $right)) {
$joined[] = array_merge($left[$key], $right[$key]);
foreach ($left as $row) {
$keyVal = $row[$leftKey];
//if this keyvalue exists in the right array, join them
if (keyval_to_index($right, $rightKey, $keyVal, $index)) {
$joined[] = array_merge($row, $right[$index]);
}
else {
$joined[] = $left[$key];
$joined[] = $row;
}
}
}
//inner join
elseif ($type = 'inner') {
foreach ($left as $key => $row) {
if (array_key_exists($key, $right)) {
$joined[] = array_merge($left[$key], $right[$key]);
foreach ($left as $row) {
$keyVal = $row[$leftKey];
//if this keyvalue exists in the right array, join them
if (keyval_to_index($right, $rightKey, $keyVal, $index)) {
$joined[] = array_merge($row, $right[$index]);
}
}
}

return $joined;
}

//finds a value in a column in an array and returns the index of the array element
function keyval_to_index($array, $key, $keyval, &$index) {
if (!is_array($array)) return false;
foreach ($array as $index => $row) {
if ($row[$key] == $keyval) return true;
}
return false;
}

//returns how long the timer as been running in seconds
function timer_stop($index)
{
Expand Down
11 changes: 11 additions & 0 deletions include/itemclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
* cap bag slots to 10
* April 6, 2020 - Maudigan
* made bag cap a constant
* July 28, 2020 - Maudigan
* cached the items db row in constructor
* added a function to get a column value from the db row
*
***************************************************************************/

Expand Down Expand Up @@ -81,6 +84,9 @@ class item {
var $myvslot;
//if it goes in a bag, this is 1-10 for which bag slot

var $myrow;
//cache the items db row

var $myaugshtml = array();
var $myaugsname = array();
var $myaugsid = array();
Expand All @@ -98,6 +104,7 @@ public function addaug($row){
}

public function item($row) {
$this->myrow = $row;
$this->myslot = $row['myslot'];
$this->myhtml = GetItem($row);
$this->myslotcount = $row['bagslots'];
Expand Down Expand Up @@ -283,6 +290,10 @@ public function item($row) {
}


function fetchColumn($col) {
return $this->myrow[$col];
}

function aughtml($key) {
return $this->myaugshtml[$key];
}
Expand Down
39 changes: 39 additions & 0 deletions include/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
$language['BAZAAR_SEARCH_CLASS'] = "Class";
$language['BAZAAR_SEARCH_RACE'] = "Race";
$language['BAZAAR_SEARCH_SLOT'] = "Slot";
$language['BAZAAR_SEARCH_STAT'] = "Stat";
$language['BAZAAR_SEARCH_TYPE'] = "Type";
//the following 4 arrays are for the dropdown select boxes on the bazaar search page
$language['BAZAAR_ARRAY_SEARCH_TYPE'] = array (
Expand Down Expand Up @@ -261,6 +262,43 @@
16384 => 'FRG',
32768 => 'DRK' //added 2/25/2014
);
$language['BAZAAR_ARRAY_SEARCH_STAT'] = array (
-1 => 'Any Stat',
'ac' => 'Armor Class',
'aagi' => 'Agility',
'acha' => 'Charisma',
'adex' => 'Dexterity',
'aint' => 'Intelligence',
'asta' => 'Stamina',
'astr' => 'Strength',
'awis' => 'Wisdom',
'cr' => 'Vs Cold',
'dr' => 'Vs Disease',
'fr' => 'Vs Fire',
'mr' => 'Vs Magic',
'pr' => 'Vs Poison',
'hp' => 'Hit Points',
'mana' => 'Mana',
'endur' => 'Endurance',
'attack' => 'Attack',
'regen' => 'HP Regen',
'manaregen' => 'Mana Regen',
'haste' => 'Haste',
'damageshield' => 'Damage Shield',
'dsmitigation' => 'Damage Shield Mitig',
'healamt' => 'Heal Amount',
'spelldmg' => 'Spell Damage',
'clairvoyance' => 'Clairvoyance',
'heroic_agi' => 'Heroic Agility',
'heroic_cha' => 'Heroic Charisma',
'heroic_dex' => 'Heroic Dexterity',
'heroic_int' => 'Heroic Intelligence',
'heroic_sta' => 'Heroic Stamina',
'heroic_str' => 'Heroic Strength',
'heroic_wis' => 'Heroic Wisdom',
'backstabdmg' => 'Backstab',
'extradmgsamt' => 'Extra Damage'
);

//alternate abilities language
$language['AAS_ALTERNATE_ABILITIES'] = "Alternate Abilities";
Expand Down Expand Up @@ -596,6 +634,7 @@
$language['MESSAGE_ORDER_ALPHA'] = "A searches order by field can only contain alphabetic characters.";
$language['MESSAGE_START_NUMERIC'] = "A searches start field can only contain numeric characters.";
$language['MESSAGE_PRICE_NUMERIC'] = "A searches price field can only contain numeric characters.";
$language['MESSAGE_STAT_INVALID'] = "The selected stat is invalid.";
$language['MESSAGE_CLASS_NUMERIC'] = "A searches class field can only contain numeric characters.";
$language['MESSAGE_RACE_NUMERIC'] = "A searches race field can only contain numeric characters.";
$language['MESSAGE_SLOT_NUMERIC'] = "A searches slot field can only contain numeric characters.";
Expand Down
2 changes: 1 addition & 1 deletion include/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

//version information
$version = "v3.3.3";
$version = "v3.4.0";

//this file always gets replaced on a reinstall
//this gets compared to the config file version stamp
Expand Down
13 changes: 13 additions & 0 deletions templates/default/bazaar_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
<!-- END select_slot -->
</select>

<label for='stat'>{L_SEARCH_STAT}</label>
<select name='stat' id='stat'>
<!-- BEGIN select_stat -->
<option value='{select_stat.VALUE}' {select_stat.SELECTED}>{select_stat.OPTION}</option>
<!-- END select_stat -->
</select>

<label for='type'>{L_SEARCH_TYPE}</label>
<select name='type' id='type'>
<!-- BEGIN select_type -->
Expand All @@ -53,6 +60,9 @@
<th><a href="{ORDER_LINK}&orderby=Name">{L_ITEM}</a></th>
<th><a href="{ORDER_LINK}&orderby=tradercost">{L_PRICE}</a></th>
<th><a href="{ORDER_LINK}&orderby=charactername">{L_NAME}</a></th>
<!-- BEGIN switch_stat -->
<th><a href="{ORDER_LINK}&orderby={switch_stat.STAT}">{switch_stat.L_STAT}</a></th>
<!-- END switch_stat -->
</tr>
</thead>
</tbody>
Expand All @@ -61,6 +71,9 @@
<td><a hoverChild='#item{items.SLOT}' class='CB_HoverParent' href='#'>{items.NAME}</a></td>
<td>{items.PRICE}</td>
<td><a href='{INDEX_URL}?page=character&char={items.SELLER}'>{items.SELLER}</a></td>
<!-- BEGIN stat_col -->
<td>{items.stat_col.STAT}</td>
<!-- END stat_col -->
</tr>
<!-- END items -->
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion templates/default/header_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html dir='ltr'>
<head>
<title>{TITLE} {SUBTITLE}</title>
<link rel='stylesheet' href='{ROOT_URL}templates/default/style-1.4.css' type='text/css'/>
<link rel='stylesheet' href='{ROOT_URL}templates/default/style-1.5.css' type='text/css'/>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<meta http-equiv='Content-Style-Type' content='text/css'>
<!-- For Chrome for Android: -->
Expand Down
2 changes: 1 addition & 1 deletion templates/default/header_simple_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script language='JavaScript' type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>
<script language='JavaScript' type='text/javascript' src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id='charbrowser'>
<link rel='stylesheet' href='{ROOT_URL}templates/default/style-1.4.css' type='text/css'/>
<link rel='stylesheet' href='{ROOT_URL}templates/default/style-1.5.css' type='text/css'/>

<div class='WindowComplex PositionHeaderSimple CB_Can_Drag'>
<div class='WindowTitleBar'>{L_NAVIGATE}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ BODY.CB_Body {


#charbrowser .PositionBazaar {
width: 625px;
width: 825px;
margin: 0 auto;
position: relative;
}
Expand Down Expand Up @@ -1484,7 +1484,7 @@ BODY.CB_Body {
}
#charbrowser .PositionBazaarRight {
display: inline-block;
width: 450px;
width: 650px;
min-height: 500px;
}

Expand Down

0 comments on commit 6588dcf

Please sign in to comment.