Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inventory action #313

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
'item' => array(
'index' => AccountLevel::ANYONE,
'view' => AccountLevel::ANYONE,
'iteminfo' => AccountLevel::ADMIN
'iteminfo' => AccountLevel::ADMIN,
'inventory' => AccountLevel::ANYONE
),
'monster' => array(
'index' => AccountLevel::ANYONE,
Expand Down Expand Up @@ -250,6 +251,7 @@
'SeeAccountID' => AccountLevel::LOWGM, // Minimum group level required to see Account ID on account view and character view pages.
'SeeUnknownItems' => AccountLevel::LOWGM, // Minimum group level required to see unidentified items as identified.
'AvoidSexChangeCost' => AccountLevel::LOWGM, // Avoid paying cost (if any) for sex changes.
'SeeItemUniqueID' => AccountLevel::LOWGM, // Ability to see item unique ID.

'EditHigherPower' => AccountLevel::NOONE,
'BanHigherPower' => AccountLevel::NOONE
Expand Down
8 changes: 8 additions & 0 deletions config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@
// Item random options.
'RandomOptions' => include('item_randoptions.php'),

// List of storages.
'StorageTables' => array(
'inventory',
'cart_inventory',
'storage',
'guild_storage',
),

// DON'T TOUCH. THIS IS FOR DEVELOPERS.
'FluxTables' => array(
'CreditsTable' => 'cp_credits',
Expand Down
8 changes: 8 additions & 0 deletions lang/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'ItemCard2Label' => 'Slot 3',
'ItemCard3Label' => 'Slot 4',
'ItemRandOptionsLabel' => 'Random options',
'EnchantGradeClass' => array( "None", "D", "C", "B", "A"),

//SIDEBAR
//FluxCP Menu Items
Expand Down Expand Up @@ -837,5 +838,12 @@
// Module: webcommands
'WCTitleLabel' => 'Web Commands',

//Storage names
'StorageGroup' => array(
'Inventory',
'Cart Inventory',
'Storage',
'Guild Storage'
),
);
?>
20 changes: 20 additions & 0 deletions lib/Flux/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,26 @@ public function linkToCharacter($charID, $text, $server = null)
}
}

/**
* $table: 0 - inventory table / 1 - cart inventory / 2 - storage table / 3 - guild storage
* It can be changed in application.php
*/
public function linkToInventoryItem($index, $text, $table = 0, $server = null)
{
if ($index) {
$params = array('type' => (int)$table, 'index' => $index);
if ($server) {
$params['preferred_server'] = $server;
}

$url = $this->url('item', 'inventory', $params);
return sprintf('<a href="%s" class="link-to-item">%s</a>', $url, htmlspecialchars($text));
}
else {
return false;
}
}

/**
* Deny entry to a page if called. This method should be used from a module
* script, and no where else.
Expand Down
136 changes: 136 additions & 0 deletions modules/item/inventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
if (!defined('FLUX_ROOT')) exit;

$type = (int)$params->get('type');
$index = $params->get('index');
$storageTable = Flux::config('StorageTables.'.$type);

$title = 'Viewing '.htmlspecialchars(Flux::message('StorageGroup.'.$type)).' Item';

require_once 'Flux/TemporaryTable.php';

if($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.item_db_re", "{$server->charMapDatabase}.item_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.item_db", "{$server->charMapDatabase}.item_db2");
}
$tableName = "{$server->charMapDatabase}.items";
$tempTable = new Flux_TemporaryTable($server->connection, $tableName, $fromTables);
$shopTable = Flux::config('FluxTables.ItemShopTable');
$itemDescTable = Flux::config('FluxTables.ItemDescTable');

// Get item id from storage
$col = "nameid, refine, attribute, bound, unique_id, enchantgrade, ";
$col .= "card0, card1, card2, card3, ";
$col .= "option_id0, option_val0, option_id1, option_val1, option_id2, option_val2, option_id3, option_val3, option_id4, option_val4";
$sql = "SELECT $col FROM {$server->charMapDatabase}.$storageTable WHERE id = ?";
$sth = $server->connection->getStatement($sql);
$sth->execute(array($index));
$itemData = $sth->fetch();

if($server->isRenewal) {
$temp = array();
if ($itemData->option_id0) array_push($temp, array($itemData->option_id0, $itemData->option_val0));
if ($itemData->option_id1) array_push($temp, array($itemData->option_id1, $itemData->option_val1));
if ($itemData->option_id2) array_push($temp, array($itemData->option_id2, $itemData->option_val2));
if ($itemData->option_id3) array_push($temp, array($itemData->option_id3, $itemData->option_val3));
if ($itemData->option_id4) array_push($temp, array($itemData->option_id4, $itemData->option_val4));
$itemData->rndopt = $temp;
}

$itemID = $itemData->nameid;

$job_list = array_keys($this->GetJobsList($server->isRenewal));
$class_list = array_keys($this->GetClassList($server->isRenewal));
$equip_list = array_keys(Flux::config('EquipLocations')->toArray());
$trade_list = array_keys(Flux::config('TradeRestriction')->toArray());

$col = 'items.id AS item_id, name_aegis AS identifier, ';
$col .= 'name_english AS name, type, subtype, ';
$col .= 'price_buy, price_sell, weight/10 AS weight, attack, defense, `range`, slots, gender, ';
$col .= 'weapon_level, equip_level_min, equip_level_max, refineable, view, alias_name, ';
$col .= 'script, equip_script, unequip_script, origin_table, ';
$col .= implode(', ', $job_list).', '; // Job list
$col .= implode(', ', $class_list).', '; // Class list
$col .= implode(', ', $equip_list).', ';
$col .= implode(', ', $trade_list).', '; // Trade restriction list

$col .= "$shopTable.cost, $shopTable.id AS shop_item_id, ";
if(Flux::config('ShowItemDesc')){
$col .= 'itemdesc, ';
}
if($server->isRenewal) $col .= 'magic_attack, ';
$col .= 'origin_table';

$sql = "SELECT $col FROM {$server->charMapDatabase}.items ";
$sql .= "LEFT OUTER JOIN {$server->charMapDatabase}.$shopTable ON $shopTable.nameid = items.id ";
if(Flux::config('ShowItemDesc')){
$sql .= "LEFT OUTER JOIN {$server->charMapDatabase}.$itemDescTable ON $itemDescTable.itemid = items.id ";
}
$sql .= "WHERE items.id = ? LIMIT 1";

$sth = $server->connection->getStatement($sql);
$sth->execute(array($itemID));

$item = $sth->fetch();
$isCustom = null;

if ($item) {
$title = "Viewing Item ($item->name)";
$isCustom = (bool)preg_match('/item_db2$/', $item->origin_table);

// Jobs
$jobs = array();
foreach($job_list as $job) if($item->$job) $jobs[] = $job;
// Classes
$upper = array();
foreach($class_list as $class) if($item->$class) $upper[] = $class;
// Equip location
$equip_locs = array();
foreach($equip_list as $eq_loc) if($item->$eq_loc) $equip_locs[] = $eq_loc;
// Trade restrictions
$restrictions = array();
foreach($trade_list as $trade) if($item->$trade) $restrictions[] = $trade;

$cardIDs = array();
$item_cards = array();

$itemData->cardsOver = -$item->slots;

if ($itemData->card0) {
$cardIDs[] = $itemData->card0;
$itemData->cardsOver++;
}
if ($itemData->card1) {
$cardIDs[] = $itemData->card1;
$itemData->cardsOver++;
}
if ($itemData->card2) {
$cardIDs[] = $itemData->card2;
$itemData->cardsOver++;
}
if ($itemData->card3) {
$cardIDs[] = $itemData->card3;
$itemData->cardsOver++;
}

if ($itemData->card0 == 254 || $itemData->card0 == 255 || $itemData->card0 == -256 || $itemData->cardsOver < 0) {
$itemData->cardsOver = 0;
}

if ($cardIDs) {
$ids = implode(',', array_fill(0, count($cardIDs), '?'));
$sql = "SELECT id, name_english FROM {$server->charMapDatabase}.items WHERE id IN ($ids)";
$sth = $server->connection->getStatement($sql);

$sth->execute($cardIDs);
$temp = $sth->fetchAll();

if ($temp) {
foreach ($temp as $card) {
$item_cards[$card->id] = $card->name_english;
}
}
}
}
?>
4 changes: 3 additions & 1 deletion themes/default/account/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class="block-link">
<?php $icon = $this->iconImage($item->nameid) ?>
<tr>
<td align="right">
<?php if ($auth->actionAllowed('item', 'view')): ?>
<?php if ($auth->actionAllowed('item', 'inventory')): ?>
<?php echo $this->linkToInventoryItem($item->id, $item->nameid, 2) ?>
<?php elseif ($auth->actionAllowed('item', 'view')): ?>
<?php echo $this->linkToItem($item->nameid, $item->nameid) ?>
<?php else: ?>
<?php echo htmlspecialchars($item->nameid) ?>
Expand Down
20 changes: 18 additions & 2 deletions themes/default/character/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,15 @@
<?php foreach ($items AS $item): ?>
<?php $icon = $this->iconImage($item->nameid) ?>
<tr<?php if ($item->equip) echo ' class="equipped"' ?>>
<td align="right"><?php echo $this->linkToItem($item->nameid, $item->nameid) ?></td>
<td align="right">
<?php if ($auth->actionAllowed('item', 'inventory')): ?>
<?php echo $this->linkToInventoryItem($item->id, $item->nameid, 0) ?>
<?php elseif ($auth->actionAllowed('item', 'view')): ?>
<?php echo $this->linkToItem($item->nameid, $item->nameid) ?>
<?php else: ?>
<?php echo htmlspecialchars($item->nameid) ?>
<?php endif ?>
</td>
<?php if ($icon): ?>
<td><img src="<?php echo htmlspecialchars($icon) ?>" /></td>
<?php endif ?>
Expand Down Expand Up @@ -523,7 +531,15 @@
<?php foreach ($cart_items AS $cart_item): ?>
<?php $icon = $this->iconImage($cart_item->nameid) ?>
<tr>
<td align="right"><?php echo $this->linkToItem($cart_item->nameid, $cart_item->nameid) ?></td>
<td align="right">
<?php if ($auth->actionAllowed('item', 'inventory')): ?>
<?php echo $this->linkToInventoryItem($cart_item->id, $cart_item->nameid, 1) ?>
<?php elseif ($auth->actionAllowed('item', 'view')): ?>
<?php echo $this->linkToItem($cart_item->nameid, $cart_item->nameid) ?>
<?php else: ?>
<?php echo htmlspecialchars($cart_item->nameid) ?>
<?php endif ?>
</td>
<?php if ($icon): ?>
<td><img src="<?php echo htmlspecialchars($icon) ?>" /></td>
<?php endif ?>
Expand Down
10 changes: 9 additions & 1 deletion themes/default/guild/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@
<?php foreach ($items AS $item): ?>
<?php $icon = $this->iconImage($item->nameid) ?>
<tr>
<td align="right"><?php echo $this->linkToItem($item->nameid, $item->nameid) ?></td>
<td align="right">
<?php if ($auth->actionAllowed('item', 'inventory')): ?>
<?php echo $this->linkToInventoryItem($item->id, $item->nameid, 0) ?>
<?php elseif ($auth->actionAllowed('item', 'view')): ?>
<?php echo $this->linkToItem($item->nameid, $item->nameid) ?>
<?php else: ?>
<?php echo htmlspecialchars($item->nameid) ?>
<?php endif ?>
</td>
<?php if ($icon): ?>
<td><img src="<?php echo htmlspecialchars($icon) ?>" /></td>
<?php endif ?>
Expand Down
Loading