<?php
require_once ("data_class.php");
class Inventory extends Data {
function Init() {
$this->GetUserData();
}
function Sell($item, $price) {
$item = mysql_real_escape_string($item);
$price = mysql_real_escape_string($price);
echo "<table width='560' align='left' border='0'>";
//echo "$item, $price";
$q = mysql_query("UPDATE creature_inventory SET qty = qty - 1 WHERE item = '$item' AND creature = '".$this->creature[user_id]."'");
$u = mysql_query("UPDATE player_creatures SET gold = gold + $price WHERE user_id = '".$this->creature[user_id]."'");
echo "<tr><td>Item sold for $price gold. <br /><br /><a href='?p=inv'>Back to inventory</a></td></tr>";
echo "</table>";
}
function Equip($item) {
$item = mysql_real_escape_string($item);
$q = mysql_query("UPDATE creature_inventory SET equipped = 1 WHERE item = '$item' AND creature = '".$this->creature[user_id]."'");
echo "<table width='560' align='left' border='0'>";
echo "<tr><td>Item equipped. It's powers are now yours.<br /><br /><a href='?p=inv'>Back to inventory</a></td></tr>";
echo "</table>";
}
function TakeOff($item) {
$q = mysql_query("UPDATE creature_inventory SET equipped = 0 WHERE item = '$item' AND creature = '".$this->creature[user_id]."'");
echo "<table width='560' align='left' border='0'>";
echo "<tr><td>Item taken off. It won't have any effect on you anymore. <br /><br /><a href='?p=inv'>Back to inventory</a></td></tr>";
echo "</table>";
}
function ItemList() {
$this->Init();
$item = mysql_real_escape_string($_POST["item"]);
$price = mysql_real_escape_string($_POST["price"]);
if (isset($_POST["sell"])) {
$this->Sell($item, $price);
}
else
if (isset($_POST["equip"])) {
$this->Equip($item);
}
else
if (isset($_POST["takeoff"])) {
$this->TakeOff($item);
}
else {
$it = mysql_query("
SELECT
creature_inventory.creature,
creature_inventory.item,
creature_inventory.equipped,
creature_inventory.qty,
shop_items.id,
shop_items.iname,
shop_items.price,
shop_items.description,
shop_items.special
FROM
creature_inventory,
shop_items
WHERE
creature_inventory.creature = '".$this->creature[user_id]."'
AND
shop_items.id = creature_inventory.item
AND
creature_inventory.qty > 0
ORDER by id ASC
");
echo "<table width='560' align='left' border='0'>";
echo "<tr><td colspan='5' style='border-bottom: 1px solid #ccc;'>My inventory | Items are sold back to merchant for 50% value default.</td></tr>";
echo "<tr><td style='border-bottom: 1px solid #ccc;'>Item</td>
<td style='border-bottom: 1px solid #ccc;'>Special</td>
<td style='border-bottom: 1px solid #ccc;'>Equipped</td>
<td style='border-bottom: 1px solid #ccc;'>Qty</td>
<td style='border-bottom: 1px solid #ccc;'>Action</td></tr>";
$i = 1;
$max = mysql_num_rows($it);
while ($i <= $max) {
$this->item[$i] = mysql_fetch_assoc($it);
$price = $this->item[$i][price] / 2;
if ($this->item[$i][equipped] == 0) {
$eqstatus = 'No';
$action1 = "<input type='submit' name='sell' value='Sell'/>";
$action2 = "<input type='submit' name='equip' value='Equip'/>";
}
else {
$eqstatus = 'Yes';
$action1 = "<input type='submit' name='sell' value='Sell'/>";
$action2 = "<input type='submit' name='takeoff' value='Take off'/>";
}
echo "<tr><td width='150' valign='top'><b title='header=[Item info] body=[".$this->item[$i][description]."]'>".$this->item[$i][iname]."</b></td>";
echo "<td width='80' valign='top' style='text-transform: uppercase;'>".$this->item[$i][special]."</td>
<td width='70' valign='top'>$eqstatus</td>
<td width='50' valign='top'>".$this->item[$i][qty]."</td>
<td width='150' valign='top'><form action='?p=inv' method='post'>
<input type='hidden' value='".$this->item[$i][item]."' name='item' />
<input type='hidden' value='".$price."' name='price' />$action1 | $action2</form></td>
</tr>";
$i++;
}
echo "<tr><td colspan='3'></td></tr>";
echo "</table>";
}
}
}
?>