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 page for listing vending items #193

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions config/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
'vending' => array(
'index' => AccountLevel::ANYONE,
'viewshop' => AccountLevel::ANYONE,
'items' => AccountLevel::ANYONE,
),
'webcommands' => array(
'index' => AccountLevel::ADMIN,
Expand Down
1 change: 1 addition & 0 deletions config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@

'vending' => array(
'index' => 'Vendors',
'items' => 'List Items',
),
),

Expand Down
92 changes: 92 additions & 0 deletions modules/vending/items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
if (!defined('FLUX_ROOT')) {
exit;
}

require_once 'Flux/TemporaryTable.php';

$title = "Items for Sale";

try {
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");
}
$itemDB = "{$server->charMapDatabase}.items";
$tempTable = new Flux_TemporaryTable($server->connection, $itemDB, $fromTables);

$bind = array();
$sqlpartial = "WHERE 1=1 ";
$itemName = $params->get('name');

if ($itemName) {
$sqlpartial .= "AND (i.name_japanese LIKE ? OR i.name_japanese = ?) ";
$bind[] = "%$itemName%";
$bind[] = $itemName;
}

$sql = "SELECT COUNT(vending_id) AS total FROM vending_items AS vi "
. "LEFT JOIN cart_inventory AS ci on ci.id = vi.cartinventory_id "
. "LEFT JOIN items i ON i.id = ci.nameid ";
$sth = $server->connection->getStatement("$sql $sqlpartial");
$sth->execute($bind);
$paginator = $this->getPaginator($sth->fetch()->total);

$sortable = array('title' => 'asc', 'merchant', 'item_name');
$paginator->setSortableColumns($sortable);

$cols = "i.name_japanese AS item_name, i.slots, i.type"
. ", vi.cartinventory_id, vi.amount, vi.price"
. ", v.title, v.map, v.x, v.y, v.id AS shop_id, char.name AS merchant"
. ", ci.nameid AS item_id, ci.refine, ci.card0, ci.card1, ci.card2, ci.card3";
$sql = "SELECT $cols FROM vending_items AS vi "
. "LEFT JOIN cart_inventory AS ci on vi.cartinventory_id = ci.id "
. "LEFT JOIN vendings AS v ON v.id = vi.vending_id "
. "LEFT JOIN `char` ON `char`.char_id = v.char_id "
. "LEFT JOIN items AS i ON i.id = ci.nameid ";
$sql = $paginator->getSQL("$sql $sqlpartial");
$sth = $server->connection->getStatement($sql);
$sth->execute($bind);
$items = $sth->fetchAll();

$cards = array();
$itemAttributes = Flux::config('Attributes')->toArray();
if ($items) {
$cardIDs = array();

foreach ($items as $item) {
$item->cardsOver = -$item->slots;

for ($n = 0; $n <= 3; $n++) {
$idx = "card$n";
if ($item->$idx) {
if (!in_array($item->$idx, $cardIDs)) {
$cardIDs[] = $item->$idx;
}
$item->cardsOver++;
}
}

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

if ($cardIDs) {
$ids = implode(',', array_fill(0, count($cardIDs), '?'));
$sql = "SELECT id, name_japanese 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) {
$cards[$card->id] = $card->name_japanese;
}
}
}
}
} catch (Exception $e) {
$items = array();
}
141 changes: 141 additions & 0 deletions themes/default/vending/items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php if (!defined('FLUX_ROOT')) exit; ?>
<h2><?php echo htmlspecialchars($title); ?></h2>
<p class="toggler"><a href="javascript:toggleSearchForm()">Search...</a></p>
<form class="search-form" method="get">
<?php echo $this->moduleActionFormInputs($params->get('module'), $params->get('action')); ?>
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo htmlspecialchars($params->get('name')) ?>" />
...
<input type="submit" value="Search" />
<input type="button" value="Reset" onclick="reload()" />
</p>
</form>
<?php if ($items): ?>
<?php echo $paginator->infoText() ?>
<table class="horizontal-table">
<thead>
<tr>
<th><?php echo $paginator->sortableColumn('title', 'Shop'); ?></th>
<th><?php echo $paginator->sortableColumn('merchant', 'Merchant'); ?></th>
<th>Position</th>
<th><?php echo $paginator->sortableColumn('item_name', 'Item Name'); ?></th>
<th>Card0</th>
<th>Card1</th>
<th>Card2</th>
<th>Card3</th>
<th>Price</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td>
<a href="<?php echo $this->url('vending', 'viewshop', array("id" => $item->shop_id)); ?>"><?php echo $item->title; ?></a>
</td>
<td><?php echo $item->merchant; ?></td>
<td>
<?php echo sprintf('%s %s, %s', $item->map, $item->x, $item->y); ?>
</td>
<td>
<?php if ($itemImage = $this->iconImage($item->item_id)): ?>
<img src="<?php echo "$itemImage?nocache=" . rand() ?>" />
<?php endif; ?>
<?php if ($item->refine > 0): ?>
<strong>+<?php echo $item->refine ?></strong>
<?php endif; ?>

<?php if ($item->card0 == 255 && intval($item->card1 / 1280) > 0): ?>
<?php $itemcard1 = intval($item->card1/1280); ?>
<?php for ($i = 0; $i < $itemcard1; $i++): ?>
Very
<?php endfor ?>
Strong
<?php endif ?>

<?php if ($item->card0 == 254 || $item->card0 == 255): ?>
<?php if ($item->char_name): ?>
<?php echo htmlspecialchars($item->char_name . "'s") ?>
<?php else: ?>
<span class="not-applicable"><?php echo htmlspecialchars(Flux::message('UnknownLabel')) ?></span>'s
<?php endif ?>
<?php endif ?>

<?php if ($item->card0 == 255 && array_key_exists($item->card1 % 1280, $itemAttributes)): ?>
<?php echo htmlspecialchars($itemAttributes[$item->card1 % 1280]) ?>
<?php endif ?>
<?php if ($auth->actionAllowed('item', 'view')): ?>
<a href="<?php echo $this->url('item', 'view', array("id" => $item->item_id)); ?>"><?php echo $item->item_name; ?></a>
<?php else: ?>
<?php echo $item->item_name ?>
<?php endif ?>
<?php if ($item->char_name): ?>
Of <?php echo $item->char_name ?>
<?php endif; ?>
<?php if ($item->slots): ?>
<?php echo htmlspecialchars(' [' . $item->slots . ']') ?>
<?php endif; ?>
</td>
<td>
<?php if ($item->card0 && ($item->type == 4 || $item->type == 5) && $item->card0 != 254 && $item->card0 != 255 && $item->card0 != -256): ?>
<?php if (!empty($cards[$item->card0])): ?>
<?php echo $this->linkToItem($item->card0, $cards[$item->card0]) ?>
<?php else: ?>
<?php echo $this->linkToItem($item->card0, $item->card0) ?>
<?php endif ?>
<?php else: ?>
<span class="not-applicable">None</span>
<?php endif ?>
</td>
<td>
<?php if ($item->card1 && ($item->type == 4 || $item->type == 5) && $item->card0 != 255 && $item->card0 != -256): ?>
<?php if (!empty($cards[$item->card1])): ?>
<?php echo $this->linkToItem($item->card1, $cards[$item->card1]) ?>
<?php else: ?>
<?php echo $this->linkToItem($item->card1, $item->card1) ?>
<?php endif ?>
<?php else: ?>
<span class="not-applicable">None</span>
<?php endif ?>
</td>
<td>
<?php if ($item->card2 && ($item->type == 4 || $item->type == 5) && $item->card0 != 254 && $item->card0 != 255 && $item->card0 != -256): ?>
<?php if (!empty($cards[$item->card2])): ?>
<?php echo $this->linkToItem($item->card2, $cards[$item->card2]) ?>
<?php else: ?>
<?php echo $this->linkToItem($item->card2, $item->card2) ?>
<?php endif ?>
<?php else: ?>
<span class="not-applicable">None</span>
<?php endif ?>
</td>
<td>
<?php if ($item->card3 && ($item->type == 4 || $item->type == 5) && $item->card0 != 254 && $item->card0 != 255 && $item->card0 != -256): ?>
<?php if (!empty($cards[$item->card3])): ?>
<?php echo $this->linkToItem($item->card3, $cards[$item->card3]) ?>
<?php else: ?>
<?php echo $this->linkToItem($item->card3, $item->card3) ?>
<?php endif ?>
<?php else: ?>
<span class="not-applicable">None</span>
<?php endif ?>
</td>

<td style="color:goldenrod; text-shadow:1px 1px 0px brown;">
<?php echo number_format($item->price, 0, ',', ' '); ?> z
</td>

<td>
<?php echo $item->amount ?>
</td>

</tr>

<?php endforeach ?>
</tbody>
</table>
<?php echo $paginator->getHTML() ?>
<?php else: ?>
<p>No Items found. <a href="javascript:history.go(-1)">Go back</a>.</p>
<?php endif ?>