Topic: Shop Mod (Item Shop 1.5)
OK, for some reason none of us can find the thread that was put up months ago about the Item Shop mod that people were wanting. I will just post another topic here in punbb about it then.
This is a stand alone mod that works with the cash mod, you must have the cash mod enabled/working on your forum for the item shop to function properly.
WARNING:
Now, this is NOT A FINISHED PROJECT.
It is missing the final part of the category feature with pagenating and ordering. However, the included list is what has already been done AND tested for errors and bugs.
Install Mod:
<?php
/***********************************************************************/
// Some info about your mod.
$mod_title = 'Shop/Item Mod';
$mod_version = '1.5';
$release_date = '3/14/2008';
$author = 'Smartys, Lunactic Inferno, Mark';
$author_email = 'smartys@punbb.org, LunacticInferno@gmail.com, Mark@sharingyour.info';
// Versions of PunBB this mod was created for.
$punbb_versions = array('1.2', '1.2.1', '1.2.2', '1.2.3', '1.2.4', '1.2.5', '1.2.6', '1.2.7', '1.2.8', '1.2.9', '1.2.10', '1.2.11', '1.2.12', '1.2.13', '1.2.14', '1.2.15', '1.2.16', '1.2.17');
// Set this to false if you haven't implemented the restore function (see below)
$mod_restore = false;
// This following function will be called when the user presses the "Install" button
function install()
{
global $db, $db_type, $pun_config;
switch ($db_type)
{
case 'mysql':
case 'mysqli':
$sql = 'CREATE TABLE '.$db->prefix.'items (
item_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
item_name VARCHAR(255) NOT NULL DEFAULT "New item",
description TEXT NOT NULL,
item_cost INT(10) UNSIGNED NOT NULL DEFAULT 0,
item_quantity INT(10) UNSIGNED NOT NULL DEFAULT 0,
item_rarity INT(10) UNSIGNED NOT NULL DEFAULT 1,
item_image VARCHAR(255) NOT NULL,
PRIMARY KEY(item_id)
) ENGINE=MyISAM';
break;
case 'pgsql':
$sql = 'CREATE TABLE '.$db->prefix.'items (
item_id SERIAL,
item_name VARCHAR(255) NOT NULL DEFAULT "New item",
description TEXT NOT NULL,
item_cost INT NOT NULL DEFAULT 0,
item_quantity INT NOT NULL DEFAULT 0,
item_rarity INT NOT NULL DEFAULT 1,
item_image VARCHAR(255) NOT NULL,
PRIMARY KEY(item_id)
)';
break;
case 'sqlite':
$sql = 'CREATE TABLE '.$db->prefix.'items (
item_id INTEGER NOT NULL,
item_name VARCHAR(255) NOT NULL DEFAULT "New item",
description TEXT NOT NULL,
item_cost INTEGER NOT NULL DEFAULT 0,
item_quantity INTEGER NOT NULL DEFAULT 0,
item_rarity INTEGER NOT NULL DEFAULT 1,
item_image VARCHAR(255) NOT NULL,
PRIMARY KEY(item_id)
)';
break;
}
$db->query($sql) or error('Unable to create items table', __FILE__, __LINE__, $db->error());
switch ($db_type)
{
case 'mysql':
case 'mysqli':
$sql = 'CREATE TABLE '.$db->prefix.'inventory (
item_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
user_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
quantity INT(10) UNSIGNED NOT NULL DEFAULT 0,
description TEXT NOT NULL,
PRIMARY KEY(item_id, user_id)
) ENGINE=MyISAM';
break;
case 'pgsql':
$sql = 'CREATE TABLE '.$db->prefix.'inventory (
item_id INT NOT NULL DEFAULT 0,
user_id INT NOT NULL DEFAULT 0,
quantity INT NOT NULL DEFAULT 0,
description TEXT NOT NULL,
PRIMARY KEY(item_id, user_id)
)';
break;
case 'sqlite':
$sql = 'CREATE TABLE '.$db->prefix.'inventory (
item_id INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL DEFAULT 0,
quantity INTEGER NOT NULL DEFAULT 0,
description TEXT NOT NULL,
PRIMARY KEY(item_id, user_id)
)';
break;
}
$db->query($sql) or error('Unable to create items table', __FILE__, __LINE__, $db->error());
}
/***********************************************************************/
// DO NOT EDIT ANYTHING BELOW THIS LINE!
// Circumvent maintenance mode
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
// We want the complete error message if the script fails
if (!defined('PUN_DEBUG'))
define('PUN_DEBUG', 1);
// Make sure we are running a PunBB version that this mod works with
$version_warning = false;
if(!in_array($pun_config['o_cur_version'], $punbb_versions))
{
foreach ($punbb_versions as $temp)
{
if (substr($temp, 0, 3) == substr($pun_config['o_cur_version'], 0, 3))
{
$version_warning = true;
break;
}
}
if (!$version_warning)
exit('You are running a version of PunBB ('.$pun_config['o_cur_version'].') that this mod does not support. This mod supports PunBB versions: '.implode(', ', $punbb_versions));
}
$style = (isset($cur_user)) ? $cur_user['style'] : $pun_config['o_default_style'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $mod_title ?> installation</title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_config['o_default_style'].'.css' ?>" />
</head>
<body>
<div id="punwrap">
<div id="puninstall" class="pun" style="margin: 10% 20% auto 20%">
<?php
if (isset($_POST['form_sent']))
{
if (isset($_POST['install']))
{
// Run the install function (defined above)
install();
?>
<div class="block">
<h2><span>Installation successful</span></h2>
<div class="box">
<div class="inbox">
<p>Your database has been successfully prepared for <?php echo pun_htmlspecialchars($mod_title) ?>. See readme.txt for further instructions.</p>
</div>
</div>
</div>
<?php
}
else
{
// Run the restore function (defined above)
restore();
?>
<div class="block">
<h2><span>Restore successful</span></h2>
<div class="box">
<div class="inbox">
<p>Your database has been successfully restored.</p>
</div>
</div>
</div>
<?php
}
}
else
{
?>
<div class="blockform">
<h2><span>Mod installation</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?foo=bar">
<div><input type="hidden" name="form_sent" value="1" /></div>
<div class="inform">
<p>This script will update your database to work with the following modification:</p>
<p><strong>Mod title:</strong> <?php echo pun_htmlspecialchars($mod_title).' '.$mod_version ?></p>
<p><strong>Author:</strong> <?php echo pun_htmlspecialchars($author) ?> (<a href="mailto:<?php echo pun_htmlspecialchars($author_email) ?>"><?php echo pun_htmlspecialchars($author_email) ?></a>)</p>
<p><strong>Disclaimer:</strong> Mods are not officially supported by PunBB. Mods generally can't be uninstalled without running SQL queries manually against the database. Make backups of all data you deem necessary before installing.</p>
<?php if ($mod_restore): ?> <p>If you've previously installed this mod and would like to uninstall it, you can click the restore button below to restore the database.</p>
<?php endif; ?><?php if ($version_warning): ?> <p style="color: #a00"><strong>Warning:</strong> The mod you are about to install was not made specifically to support your current version of PunBB (<?php echo $pun_config['o_cur_version']; ?>). However, in most cases this is not a problem and the mod will most likely work with your version as well. If you are uncertain about installning the mod due to this potential version conflict, contact the mod author.</p>
<?php endif; ?> </div>
<p><input type="submit" name="install" value="Install" /><?php if ($mod_restore): ?><input type="submit" name="restore" value="Restore" /><?php endif; ?></p>
</form>
</div>
</div>
<?php
}
?>
</div>
</div>
</body>
</html>
Items Page:
<?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['form_sent']))
{
$items = isset($_POST['item']) && is_array($_POST['item']) ? $_POST['item'] : array();
$deduct_cash = 0;
$deduct_quantity = array();
$sql = array();
foreach ($items as $item_id => $to_buy)
{
if ($to_buy > 0)
{
$result = $db->query('SELECT item_name, item_quantity, item_cost FROM '.$db->prefix.'items WHERE item_id = '.$item_id) or error('Unable to fetch item information', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) > 0)
{
$item_info = $db->fetch_assoc($result);
if ($to_buy > $item_info['item_quantity'])
message('You can not buy '.$to_buy.' '.pun_htmlspecialchars($item_info['item_name']).'(s): there is/are only '.$item_info['item_quantity'].' left!');
if (($to_buy * $item_info['item_cost']) > $pun_user['cm_cash'])
message('You don\'t have enough '.pun_htmlspecialchars($pun_config['cm_cur_name']).' to buy '.$to_buy.' '.pun_htmlspecialchars($item_info['item_name']).'.');
$sql[] = '('.$item_id.', '.$pun_user['id'].', '.$to_buy.')';
$deduct_cash += $to_buy * $item_info['item_cost'];
}
else
{
message($lang_common['Bad request']);
}
}
}
// If we're here, all of the items are valid to buy
foreach ($items as $item_id => $to_buy)
{
$db->query('UPDATE '.$db->prefix.'items set item_quantity = item_quantity - '.$to_buy.' WHERE item_id = '.$item_id) or error('Unable to deduct item from store', __FILE__, __LINE__, $db->error());
}
$db->query('UPDATE '.$db->prefix.'users SET cm_cash = cm_cash - '.$deduct_cash.' WHERE id = '.$pun_user['id']) or error('Unable to deduct cash', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'inventory (item_id, user_id, quantity) VALUES '.implode(',', $sql).' ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)') or error('Unable to add items to inventory', __FILE__, __LINE__, $db->error());
redirect($_SERVER['REQUEST_URI'], 'Items purchased. Redirecting …');
}
$page_title = pun_htmlspecialchars($pun_config['o_board_title'].' - Shop');
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
?>
<div class="block">
<div class="box">
<div class="inbox">
<p><strong>If you are looking to buy user account changes, then please go to the <a href="shop.php">Shop</a> which will sell these to you. This section is for Chibis, Edible Items, and Misc Items.</strong></p>
</div>
</div>
</div>
<div class="blocktable">
<h2><span>Buy some items</span></h2>
<div class="box">
<div class="inbox">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<input type="hidden" name="form_sent" value="1" />
<div class="inform">
<table cellspacing="0">
<thead>
<tr>
<th class="tc2" scope="col">Image</th>
<th class="tcl" scope="col">Item Name</th>
<th class="tc2" scope="col">Price</th>
<th class="tc3" scope="col">Rarity</th>
<th class="tc3" scope="col">Quantity Remaining</th>
<th class="tcr" scope="col">Number to Buy</th>
</tr>
</thead>
<tbody>
<?php
// Display all the categories and forums
$result = $db->query('SELECT * FROM '.$db->prefix.'items') 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 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="tc2"><?php echo $cur_item['item_cost'] ?> <?php echo pun_htmlspecialchars($pun_config['cm_cur_name']) ?></td>
<td class="tc3"><?php echo $cur_item['item_rarity'] ?></td>
<td class="tc3"><?php echo $cur_item['item_quantity'] ?></td>
<td class="tcr"><input type="text" name="item[<?php echo $cur_item['item_id'] ?>]" value="0" /></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<p class="submitend"><input type="submit" name="buy" value="Buy selected items" /></p>
</form>
</div>
</div>
</div>
<?php
require PUN_ROOT.'footer.php';
Inventory Page:
<?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.' and user_id='.$pun_user['id']) 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.' and user_id='.$pun_user['id']) 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.' and user_id='.$pun_user['id']) 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.' and user_id='.$pun_user['id']) 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.' and user_id='.$pun_user['id']) 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';
AP Items:
<?php
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
if (isset($_POST['add_item']))
{
$item_name = $db->escape(trim($_POST['item_name']));
$item_description = $db->escape(trim($_POST['item_description']));
$item_price = intval($_POST['item_price']);
$item_quantity = intval($_POST['item_quantity']);
$item_rarity = intval($_POST['item_rarity']);
$item_image = $db->escape(trim($_POST['item_image']));
if (strlen($item_name) == 0)
message('Items need names, you know.');
if (strlen($item_description) == 0)
message('Items need some info or you don\'t know what it is.');
if ($item_price < 0)
message('You can\'t sell an item for less than 0 '.$pun_config['cm_cur_name'].'.');
if ($item_quantity < 0)
message('You can\'t have a negative number of an item in the shop.');
if ($item_rarity < 0)
message('An item may not have a negative rarity.');
if (strlen($item_image) == 0)
message('An image might be handy.');
$db->query('INSERT INTO '.$db->prefix.'items (item_name, description, item_cost, item_quantity, item_rarity, item_image) VALUES ("'.$item_name.'", "'.$item_description.'", '.$item_price.', '.$item_quantity.', '.$item_rarity.', "'.$item_image.'")') or error('Unable to add new item', __FILE__, __LINE__, $db->error());
redirect($_SERVER['REQUEST_URI'], 'Item added. Redirecting …');
}
else if (isset($_POST['update_items']))
{
while (list($item_id, $item_info) = @each($_POST['item']))
{
$item_price = intval($item_info['item_price']);
$item_description = $db->escape(trim($item_info['item_description']));
$item_quantity = intval($item_info['item_quantity']);
$item_rarity = intval($item_info['item_rarity']);
$item_image = $db->escape(trim($item_info['item_image']));
if (strlen($item_description) == 0)
message('Items need some info or you don\'t know what it is.');
if ($item_price < 0)
message('You can\'t sell an item for less than 0 '.$pun_config['cm_cur_name'].'.');
if ($item_quantity < 0)
message('You can\'t have a negative number of an item in the shop.');
if ($item_rarity < 0)
message('An item may not have a negative rarity.');
$db->query('UPDATE '.$db->prefix.'items SET description="'.$item_description.'", item_cost='.$item_price.', item_quantity='.$item_quantity.', item_rarity='.$item_rarity.' WHERE item_id='.intval($item_id)) or error('Unable to update item', __FILE__, __LINE__, $db->error());
}
redirect($_SERVER['REQUEST_URI'], 'Items updated. Redirecting …');
}
else
{
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div class="blockform">
<h2><span>Add item</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Create a new item</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Item Image</th>
<td>
<input type="text" name="item_image" size="30" maxlength="255" />
<span>The image for this item.</span>
</td>
</tr>
<tr>
<th scope="row">Item Name</th>
<td>
<input type="text" name="item_name" size="30" maxlength="255" />
<span>The name for the new item you are creating.</span>
</td>
</tr>
<th scope="row">Item Description</th>
<td>
<input type="text" name="item_description" size="20" maxlength="400" />
<span>The info for the new item you are creating.</span>
</td>
</tr>
<tr>
<th scope="row">Item Price</th>
<td>
<input type="text" name="item_price" size="8" maxlength="8" />
<span>The price for the new item you are creating.</span>
</td>
</tr>
<tr>
<th scope="row">Item Quantity</th>
<td>
<input type="text" name="item_quantity" value="1" size="3" maxlength="4" />
<span>The quantity of the new item you are creating.</span>
</td>
</tr>
<tr>
<th scope="row">Item Rarity</th>
<td>
<input type="text" name="item_rarity" value="1" size="3" maxlength="3" />
<span>The rarity of new item you are creating.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="add_item" value="Add" tabindex="<?php echo $tabindex_count ?>" /></p>
</form>
</div>
<?php
// Display all the categories and forums
$result = $db->query('SELECT '.$db->prefix.'items.* FROM '.$db->prefix.'items ORDER BY item_name') or error('Unable to fetch item list', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) > 0)
{
?>
<h2 class="block2"><span>Edit items</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<p class="submittop"><input type="submit" name="update_items" value="Update positions" tabindex="3" /></p>
<div class="inform">
<fieldset>
<legend>Item List:</legend>
<div class="infldset">
<table cellspacing="0">
<?php
$tabindex_count = 4;
while ($cur_item = $db->fetch_assoc($result))
{
?>
<tr>
<th><?php echo pun_htmlspecialchars($cur_item['item_name']) ?></th>
<td>
Description <input type="text" name="item[<?php echo $cur_item['item_id'] ?>][item_description]" size="8" maxlength="400" value="<?php echo $cur_item['description'] ?>" tabindex="<?php echo $tabindex_count++ ?>" />
Price<input type="text" name="item[<?php echo $cur_item['item_id'] ?>][item_price]" size="8" maxlength="8" value="<?php echo $cur_item['item_cost'] ?>" tabindex="<?php echo $tabindex_count++ ?>" />
Quantity <input type="text" name="item[<?php echo $cur_item['item_id'] ?>][item_quantity]" size="3" maxlength="4" value="<?php echo $cur_item['item_quantity'] ?>" tabindex="<?php echo $tabindex_count++ ?>" />
Rarity <input type="text" name="item[<?php echo $cur_item['item_id'] ?>][item_rarity]" size="3" maxlength="3" value="<?php echo $cur_item['item_rarity'] ?>" tabindex="<?php echo $tabindex_count++ ?>" />
Image <?php echo pun_htmlspecialchars($cur_item['item_image']) ?>
</td>
</tr>
<?php
}
?>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="update_items" value="Update items" tabindex="<?php echo $tabindex_count++ ?>" /></p>
</form>
</div>
<h2 class="block2"><span>Upload Image</span></h2>
<div class="box">
<?php
$file_dir = "img/items/";
foreach($_FILES as $file_name => $file_array) {
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], $file_dir.'/'.$file_array['name']) or die("Couldn't copy.");
}
}
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<div class="inform">
<fieldset>
<legend>Image Upload</legend>
<div class="infldset">
<p><strong>File to upload:</strong>
<input type="file" name="fileupload" /></p>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="upload_image" value="Upload Image" tabindex="<?php echo $tabindex_count++ ?>" /></p>
</form>
</div>
</div>
<?php
}
}
The finished portions include the following:
AP_Items -
Item Creation
Name, Description, Rank, Quantity, Price and Image.
Item Editing
Description change, amount change, quantity change, and rank change. (At the time there is no ability to change the item image, we were not sure if we should have the image change allowed yet or not.)
Item Image Uploader
This allows you to upload an image for your items that you specified a name for. The default database is img/items as the directory.
Item Page -
Displaying created images, and the ability to buy the images. (At this time they are displayed in a random order, and there is no page cut off feature...)
Inventory Page -
A list of your 'bought' items for your personal inventory with the ability to Throw Away the item, Throw all of THAT item away, and giving the item to someone.
When you give the item away to someone they receive a private message (if your private message feature is enabled/set up correctly) that they have gotten an item from you and what that item is.
Install_Mod -
This page has all of the categories defined to be installed into your sql database for your forum.
______________________________________________________________________________________________
These are the things needing to be finished:
Category feature with ordering defined and pagenating defined.
This is an overview of what is NEEDED for the specific pages:
Install_Mod -
Category database defined for the sql database.
AP_Items -
Category code created that needs the following overview.
Create Category:
Category Name (to be created) and a checkbox list of these items to be defined (See Inventory.php for detail on this) Eat, Use, Mix, Forge, Open, Drink.
These six "actions" are basic actions that may be used in an rpg or action scripted project later to come. By creating, in example, a category named Foods you may want to "check" the actions "eat" and "mix". For weapons you may want "Forge" or "Fix".
Edit Items -
There needs to be a drop down box added to the edit items code so that you can select a category for an item to be displayed. That way, any item that is not given a category will not be displayed. This keeps items not being used or 'seasonal items' not being displayed out of season while still keeping them in the database. There is NO way to delete items already created unless you go into your sql database and do so manually. This was intended to be this way so that you can give them a category to display them or not on the items.php and inventory.php pages.
Maybe an area should be made to define how many items should be displayed on the items.php or inventory.php pages that an administrator can set? It would just have to be a small number box where you can put in "20" or "40" or whatever.
Items.php -
Side navigational bar code needs to be created to display what categories have been made so that a user can click on the category and have the items displayed to the opposite side. This keeps it nice and simple so that a user can choose to see ONLY the items of the category he selected to see, without having to file through random objects.
Pagenating and ordering needs to be set up on this page so that the 'number of items to be displayed on a page' allows less scrolling (see AP_Items for information) and the ordering of the items according to rank and alphabetical order. It should be 1-10, then alphabetically, descending.
Inventory.php -
This page needs the category code like items.php as well as pagenating and ordering, the other snippet code needed is the 'actions' area to the side is for the checkboxed 'actions' created with the specific categories in AP_Items. That way if a category has 'additional actions' checked they show up as a box to be used in the inventory.
Maybe they will have messages saying,
Eat = You have eatten item_name.
Use = You have used item_name.
Mix = You have mixed item_name.
Forge = You have forged item_name.
Open = You have opened item_name.
Drink You have dragon item_name.
______________________________________________________________________________________________
That is all for now. It is the base shop for an RPG mod someone might want to make some time. I know that my brother is making a java based rpg mod that allows you to 'synth items' by combining one or more items to make another and a duel based mod. I might post them up when they get done if it is something someone is interested in after this is finished.
If anyone has any ideas or wants to help, feel free to drop me a line here in the forum, you can find me on the punbb channel as well, or email me at LunacticInferno@gmail.com.
Thanks to Smartys for the skeleton of the shop, thanks to mark also for helping out off and on.
Included is a link to the zip ( http://aoirojoukai.validayne.net/ItemShop.zip ) with the pages you can download to try out, you can also see it in action at http://75.100.14.27/Forum/Items.php for the item page and http://75.100.14.27/Forum/Inventory.php for the inventory page.
Version 1.5 DOES work and has been tested. It only needs to be finished now.