rendered paste body<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/cash.php';
if ($pun_user['is_guest'])
message($lang_common['No view']);
if (isset($_POST['throw']) || isset($_POST['throwall']) ||isset($_POST['giveto']))
{
$iid = round($_POST['iid']);
$result = $db->query('SELECT inv.item_id, inv.quantity, it.item_name, it.item_rarity, it.item_image FROM '.$db->prefix.'inventory AS inv INNER JOIN '.$db->prefix.'items AS it ON (it.item_id=inv.item_id) WHERE user_id='.$pun_user['id'].' and inv.item_id='.$iid) or error('Unable to fetch item list', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) == 0)
message($lang_common['Bad request']);
$cur_item = $db->fetch_assoc($result);
if (isset($_POST['throw']))
{
$db->query('UPDATE '.$db->prefix.'inventory SET quantity=quantity-1 WHERE item_id='.$iid) or error('Unable to throw away', __FILE__, __LINE__, $db->error());
if ($cur_item['quantity'] == 1)
$db->query('DELETE FROM '.$db->prefix.'inventory WHERE item_id='.$iid) or error('Unable to throw away item.', __FILE__, __LINE__, $db->error());
redirect($_SERVER['REQUEST_URI'], 'You have thrown away your item.');
}
else if (isset($_POST['throwall']))
{
$db->query('DELETE FROM '.$db->prefix.'inventory WHERE item_id='.$iid) or error('Unable to throw away item.', __FILE__, __LINE__, $db->error());
redirect($_SERVER['REQUEST_URI'], 'You have thrown away your item.');
}
else if (isset($_POST['giveto']))
{
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE username=\''.$db->escape($_POST['username']).'\'') or error('Unable to find user.', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result) == 0)
message('This user does not exist.');
$user = $db->fetch_assoc($result);
$db->query('INSERT INTO '.$db->prefix.'inventory (item_id, user_id, quantity) VALUES ('.$iid.', '.$user['id'].', 1) ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)') or error('Unable to add items to inventory', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'inventory SET quantity=quantity-1 WHERE item_id='.$iid) or error('Unable to remove item from user', __FILE__, __LINE__, $db->error());
if ($cur_item['quantity'] == 1)
$db->query('DELETE FROM '.$db->prefix.'inventory WHERE item_id='.$iid) or error('Unable to delete from inventory', __FILE__, __LINE__, $db->error());
$message = 'I have given you a '.$cur_item['item_name'].' because I am so kind and thought you deserve it for all your hard work.';
$db->query('INSERT INTO '.$db->prefix.'messages (owner, subject, message, sender, sender_id, sender_ip, smileys, showed, status, posted) VALUES(
\''.$user['id'].'\',
\''.$db->escape($cur_item['item_name']).'\',
\''.$db->escape($message).'\',
\''.$db->escape($pun_user['username']).'\',
\''.$pun_user['id'].'\',
\''.get_remote_address().'\',
\''.$smilies.'\',
\'0\',
\'0\',
\''.time().'\'
)') or error('Unable to send message', __FILE__, __LINE__, $db->error());
redirect($_SERVER['REQUEST_URI'], 'You have given your item to '.$user['username']);
}
}
$page_title = pun_htmlspecialchars($pun_config['o_board_title'].' - Inventory');
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
?>
<div class="blocktable">
<h2><span>Your inventory</span></h2>
<div class="box">
<div class="inbox">
<table cellspacing="0">
<thead>
<tr>
<th class="tc3" scope="col">Image</th>
<th class="tcl" scope="col">Item Name</th>
<th class="tc2" scope="col">Rarity</th>
<th class="tc3" scope="col">Quantity Owned</th>
<th class="tcr" scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
// Display all the categories and forums
$result = $db->query('SELECT inv.item_id, inv.quantity, it.item_name,it.description, it.item_rarity, it.item_image FROM '.$db->prefix.'inventory AS inv INNER JOIN '.$db->prefix.'items AS it ON (it.item_id=inv.item_id) WHERE user_id='.$pun_user['id'].' ORDER BY item_name') or error('Unable to fetch item list', __FILE__, __LINE__, $db->error());
while ($cur_item = $db->fetch_assoc($result))
{
?>
<tr>
<td class="tc2"><img src="img/items/<?php echo pun_htmlspecialchars($cur_item['item_image']) ?>" alt="<?php echo pun_htmlspecialchars($cur_item['item_name']) ?>"/></td>
<td class="tcl"><strong><?php echo pun_htmlspecialchars($cur_item['item_name']) ?></strong><br/><br/><em><?php echo pun_htmlspecialchars($cur_item['description']) ?></em></td>
<td class="tc3"><?php echo $cur_item['item_rarity'] ?></td>
<td class="tc3"><?php echo $cur_item['quantity'] ?></td>
<td class="tcr"><form name="action" action="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
<p>
<input type="hidden" value="<?php echo $cur_item['item_id']; ?>" name="iid" />
<input type="submit" name="throw" value="Throw away" /><br />
<input type="submit" name="throwall" value="Throw away all" /><br />
<input type="submit" name="giveto" value="Give to" />
<input type="text" name="username" value="<?php echo $user['username']; ?>" />
</p>
</form></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require PUN_ROOT.'footer.php';